• 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: NSImage & memory
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage & memory


  • Subject: Re: NSImage & memory
  • From: Alastair Houghton <email@hidden>
  • Date: Tue, 17 Jul 2007 18:37:31 +0100

On 17 Jul 2007, at 18:20, Jeremy Rotsztain wrote:

Hey.

I'm running into problems managing images and memory.
I'm creating a NSImage and writing its contents to disk (by generating a TIFF representation of the NSImage).
When I try to release the NSData related to that image, my application crashes.
I'm doing some reading on memory allocation, but I can't find a straight-forward answer to my problem.
Should I be using autorelease pools?

You already are, which is in fact the root of your problem.

NSData *tmpImgTIFFData = [ tmpImg TIFFRepresentation ];

The hint is in the method name above. It does not contain the words "copy", "new" or "alloc", from which you can deduce that the thing it returns is owned by someone else (probably the current autorelease pool, though in some cases it might be owned by the NSImage itself).


[ tmpImgTIFFData writeToFile:@"/Users/kiev/Desktop/ FlickrComposition.tiff" atomically:YES ];

// release data
[ tmpImgTIFFData release ];

Anyway, here is your bug. You don't own tmpImgTIFFData, so you shouldn't release it. Your program will crash either when you release the image, or when the autorelease pool is released (probably at the end of the current event).


Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSImage & memory (From: Jeremy Rotsztain <email@hidden>)

  • Prev by Date: Re: NSImage & memory
  • Next by Date: Re: NSImage & memory
  • Previous by thread: Re: NSImage & memory
  • Next by thread: Re: NSImage & memory
  • Index(es):
    • Date
    • Thread