Re: Will this leak memory?
Re: Will this leak memory?
- Subject: Re: Will this leak memory?
- From: Chris Ridd <email@hidden>
- Date: Fri, 05 Sep 2003 15:01:11 +0100
On 5/9/03 2:36 pm, Neil Earnshaw <email@hidden> wrote:
>
Will this implementation of the Singleton pattern leak memory in Obj-C?
>
>
+(id)defaultObject
>
{
>
static MyObject* defaultObject;
>
>
if ( !defaultObject ) {
>
defaultObject = [[MyObject alloc] init];
>
}
>
return defaultObject;
>
}
>
>
-(void)dealloc
>
{
>
NSLog(@"%@ dealloc",self);
>
...
>
[super dealloc];
>
}
>
>
The dealloc log message never gets called.
Objects typically don't get sent -dealloc when a program's stopping, so it
will appear to leak, yes. If you've got exit cleanup to do, then you need to
register for NSApplicationWillTerminateNotification, and do your thing when
you get that notification.
Cheers,
Chris
_______________________________________________
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.