Re: globals and memory leaks
Re: globals and memory leaks
- Subject: Re: globals and memory leaks
- From: David Remahl <email@hidden>
- Date: Sun, 20 Apr 2003 23:04:07 +0200
On svndag, apr 20, 2003, at 22:43 Europe/Stockholm, Francisco Tolmasky
wrote:
In my program I frequently do something like this:
static NSImage * someImage;
@implementation myClass
+ (void)initialize
{
someImage= [[NSImage imageNamed: @"Some Image"] retain];
}
//...
@end
Firstly, is this the correct way to do this. Secondly, if it is,
should I be worried about memory leaks, do I have to release this
image when the program terminates?
I also do this with my shared Instances, like this:
Prefernces * sharedPrefs;
@implementation Preferences
+ (void)sharedInstance
{
if(!sharedPrefs) sharedPrefs= [[Preferences alloc] init];
return sharedPrefs;
}
Do I ever release sharedPrefs??
Thank you in advance,
Francisco Tolmasky
It is perfectly OK do to what you are doing. You do not need to worry
about releasing the objects when the program terminates, as all memory
will be deallocated and returned to the system automatically.
All of this has been discussed several times in the past. I believe you
will find some interesting discussion if you search the archives!
/ Regards, David
_______________________________________________
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.