Hello,
So, I originally started with a book, but have transitioned over to taking the Stanford CS 193p class on iTunes U, which has been a much better form of learning for me. I'm fairly early on in the class, but I had a question, and was wondering if I can get some assistance.
Take this theoretical piece of code:
Followed by:
With the note that PolygonShape has the following method, simplified:
My Console results are:
followed by an EXC_BAD_ACCESS crash.
Why is dealloc only running when the array is released and not the objects I'm running it on? Isn't it my responsibility to individually release everything I ran alloc/init on in the local scope?
Thanks for any clarification on how I'm looking at this.
So, I originally started with a book, but have transitioned over to taking the Stanford CS 193p class on iTunes U, which has been a much better form of learning for me. I'm fairly early on in the class, but I had a question, and was wondering if I can get some assistance.
Take this theoretical piece of code:
Code:
NSMutableArray *poly = [NSMutableArray alloc] init];
PolygonShape *polygon1 = [[PolygonShape alloc] init];
PolygonShape *polygon2 = [[PolygonShape alloc] init];
PolygonShape *polygon3 = [[PolygonShape alloc] init];
[poly addObject:polygon1];
[poly addObject:polygon2];
[poly addObject:polygon3];
Followed by:
Code:
[polygon1 release];
NSLog(@"test1");
[polygon2 release];
NSLog(@"test2");
[polygon3 release];
NSLog(@"test3");
[poly release];
NSLog(@"test4");
With the note that PolygonShape has the following method, simplified:
Code:
- (void)dealloc
{
NSLog(@"dealloc ran");
//release some integer ivars
[super dealloc];
}
My Console results are:
Code:
test
test2
test3
dealloc ran
followed by an EXC_BAD_ACCESS crash.
Why is dealloc only running when the array is released and not the objects I'm running it on? Isn't it my responsibility to individually release everything I ran alloc/init on in the local scope?
Thanks for any clarification on how I'm looking at this.