• 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: NSImageView setImage & when to release NSImage...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImageView setImage & when to release NSImage...


  • Subject: Re: NSImageView setImage & when to release NSImage...
  • From: "Alastair J.Houghton" <email@hidden>
  • Date: Fri, 24 Oct 2003 14:53:15 +0100

On Friday, October 24, 2003, at 12:10 pm, Brad Peterson wrote:

Hi all,

Maybe this is explained somewhere and it's just too late for me to spot it, but here goes...

If my goal is to display an image stored on disk, I might do something like...

myImage = [[NSImage alloc] initByReferencingFile:filename];
[myImageView setImage: myImage];

Yes?

So... in this scenario, when does myImage get released? Am I responsible for releasing it?

Yes, because you called -alloc.

I would think so, but I'm unclear on whether NSImageView "needs" the NSImage once you've called setImage... or, perhaps it's smart enough to release it when it's done?

NSImageView will -retain your image, and will -release it when it has finished using it. Most objects behave in a similar way... that is, their -retain and -release calls are balanced.

Can anyone clarify what is probably a very basic thing I've somehow overlooked?

Take a look at my FAQ

http://www.alastairs-place.net/cocoa/faq.txt

which has a list of simple rules you can follow to get your memory management right.

Kind regards,

Alastair.
_______________________________________________
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: 
 >NSImageView setImage & when to release NSImage... (From: "Brad Peterson" <email@hidden>)

  • Prev by Date: Re: NSTask and Notification?
  • Next by Date: RE: newbie question: unsigned index
  • Previous by thread: Re: NSImageView setImage & when to release NSImage...
  • Next by thread: Re: NSImageView setImage & when to release NSImage...
  • Index(es):
    • Date
    • Thread