small medium large xlarge

Generic-user-small
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]){ self.name = newName; self.upperCase = YES; self.today = [[NSDate alloc] init]; } return self;
}

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

Generic-user-small
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 self.today in there?

Generic-user-small
26 Oct 2009, 23:22
Thomas Wieczorek (7 posts)

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

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

You must be logged in to comment