Re: Memory management question
Re: Memory management question
- Subject: Re: Memory management question
- From: Malte Tancred <email@hidden>
- Date: Thu, 25 Mar 2004 08:13:53 +0100
On 25 mar 2004, at 00.41, Glen Simmons wrote:
<snip>
pools to clean them up as and when necessary. Alternatively, you can
immediately release any individual autoreleased object by doing
[[someObject retain] release];
(The -retain increments the reference count, removing it from the
autorelease pool, then the -release triggers the deallocation of the
object.)
<snip>
This is the first I've ever heard that retain removes an object from
the autorelease pool. How does it know that the object is even *in* an
autorelease pool? And which pool? More info please.
Why don't we try it out?
malte% cat autorelease.m
#import <Foundation/Foundation.h>
@interface Dummy : NSObject
@end
@implementation Dummy
- (id)retain {
NSLog(@"dummy retain");
return [super retain];
}
- (oneway void)release {
NSLog(@"dummy release");
[super release];
}
@end
int main() {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
id s = nil;
NSLog(@"creating");
s = [[Dummy alloc] init];
NSLog(@"autoreleasing");
[s autorelease];
NSLog(@"retain/release");
[[s retain] release];
NSLog(@"releasing pool");
[pool release];
exit(0);
return 0;
}
malte% ./autorelease
2004-03-25 08:11:31.051 autorelease[688] creating
2004-03-25 08:11:31.054 autorelease[688] autoreleasing
2004-03-25 08:11:31.055 autorelease[688] retain/release
2004-03-25 08:11:31.056 autorelease[688] dummy retain
2004-03-25 08:11:31.057 autorelease[688] dummy release
2004-03-25 08:11:31.058 autorelease[688] releasing pool
2004-03-25 08:11:31.060 autorelease[688] dummy release
Cheerio,
Malte
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.