I am not clear about how to use autorelease
;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
RetainTracker* tracker = [RetainTracker new];
[tracker retain];
[tracker retain];
[tracker autorelease];
[pool release];
Is there any memory leak in the above code?
I know the autorelease
just puts tracker
into NSAutoreleasePool
, without modifying the reference count for tracker
. When i call [pool release]
, the object receives one message release
, then the reference count of tracker
is 2
. So the compiler can't call the dealloc
function of object tracker
, so there is a memory leak.
So i get this: we shoul call retain
and release
same times, is it right?