• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: globals and memory leaks
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >globals and memory leaks (From: Francisco Tolmasky <email@hidden>)

  • Prev by Date: globals and memory leaks
  • Next by Date: finding the path to the desktop...
  • Previous by thread: globals and memory leaks
  • Next by thread: Re: globals and memory leaks
  • Index(es):
    • Date
    • Thread