[Newbie] Proper class releasing
[Newbie] Proper class releasing
- Subject: [Newbie] Proper class releasing
- From: "Jon Keon" <email@hidden>
- Date: Fri, 6 Jun 2008 12:11:57 -0400
- Thread-topic: [Newbie] Proper class releasing
Hi All,
I'm having a problem with creating new instances of classes after other
instances of them have been released.
I have a class called BaddieManager.
In this class I have a NSMutableArray that holds instances of Baddies.
So I create a new instance, place it my array and when the Baddies life
expires, I remove it from the array. This then causes the instance to
dealloc but then the next time I call my populateBaddies function the
whole program crashes with no error message. Any help would be greatly
appreciated.
Thanks,
Jon
//populate the array with baddies
-(void) populateBaddies {
while (baddieCount < baddieLimit) {
//Create a new instance of my baddie
PBaddie *newBaddie = [[PBaddie alloc] init];
//add him to the view
[gameView addSubview:newBaddie];
//give him a reference of the manager
[newBaddie attachManagerRef:self];
//animate him
[newBaddie animateBaddie:NULL finished:0];
//add him to the array
[pBaddieArray addObject:newBaddie];
//release the temp variable
[newBaddie release];
//increment the count
baddieCount = [pBaddieArray count];
}
}
//Removes the Baddie from the array and destructs him
-(void) removeMe:(PBaddie *) pBad {
//remove from the game view - we don't want to see it anymore
[pBad removeFromSuperview];
//remove the baddie from the array (Causes the Baddies dealloc
method to fire)
[pBaddieArray removeObject:pBad];
//update the count
baddieCount = [pBaddieArray count];
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden