Re: Will this leak memory?
Re: Will this leak memory?
- Subject: Re: Will this leak memory?
- From: j o a r <email@hidden>
- Date: Fri, 5 Sep 2003 15:58:12 +0200
You don't really have to implement dealloc for a singleton object,
since it will exist until the application is terminated. When the
application is terminated dealloc is sometimes ignored (as an
optimization I believe), since all memory used by the application will
be reclamed by the system in any case there is no need to spend time
deallocating individual objects at this time.
I always write a proper dealloc method in any case, it's good practice.
Also, if you at a later time decide to change the singleton into a
regular object it's good to have the dealloc in place so that you don't
forget about it.
j o a r
On fredag, september 5, 2003, at 03:36 PM, Neil Earnshaw 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.
_______________________________________________
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.