small medium large xlarge

13 Oct 2009, 21:36
David Stanley (1 post)

I followed the concepts in the new Chapter 6 on memory without difficulty. I even tried to the code. But, I seem to still have a memory leak. So I downloaded your code from the PragProg website: Flashlight 11 Project. I still keep coming up with a memory leak. The Instruments tell me the leak is in the [Greeter initWithName:] method; specifically, the _NSCFDate object (16bytes). I’m confused by this since the dealloc sets “today” to nil. Have I done something wrong? Is this a problem with code or the library? Any insights? Cheers, David Snow Leopard 10.6.1 Xcode 3.2.1 (fresh install with corresponding new iPhone tools)

-(id) initWithName:(NSString *) newName {
if (self = [super init]){ = newName; self.upperCase = YES; = [[NSDate alloc] init]; } return self;

-(void) dealloc { NSLog(@”In Greeter dealloc.”); = nil; = nil; [super dealloc]; }

20 Oct 2009, 23:17
Caroline (5 posts)

Doesn’t setting “today” to nil, only set the today pointer to nil, not release the memory? If the today pointer is nil, then it is not referencing the correct memory for it, but the memory is still being used somewhere.

Should there be a release of in there?

26 Oct 2009, 23:22
Thomas Wieczorek (7 posts)

David: I am not sure if I use the right technique, but replacing = [[NSDate alloc] init];@ with = [NSDate date];@ solved the problem with the memory leak for me. Did anyone else solved this one?

Caroline: Chapter 6.9 describes that = nil;@ is equivalent with @[today release]; today = nil;@

You must be logged in to comment