• 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: [Worse] Re: [NSImage initWithData]: Memory leak. Bug in code or in Framework?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Worse] Re: [NSImage initWithData]: Memory leak. Bug in code or in Framework?


  • Subject: Re: [Worse] Re: [NSImage initWithData]: Memory leak. Bug in code or in Framework?
  • From: Peter Ammon <email@hidden>
  • Date: Thu, 13 Dec 2007 18:30:56 -0800


On Dec 13, 2007, at 2:59 PM, Stephane Sudre wrote:


On Dec 13, 2007, at 9:04 PM, Stéphane wrote:

This simple sample code results in a memory leak in [NSImage initWithData:].

Is it a bug in Cocoa or is it a bug in the code itself?

Is there a workaround (I already tried multiple things: mutableCopy of data to releaseit after initialization, setDataRetained and different cache mode for the NSImage).

No useful pointers found in the list archive or on the net.



Note that without the distribution notification communication, it works fine (this is to illustrate a problem seen in a tool receiving dist notifications).

It looks like this is a bug in [NSBitmapImageRep imageRepsWithData:] (apparently the code used by initWithData if I am to believe the Gnustep source code) or one of its method when invoked in this mode.


If I delay the initWithData: code with a performSelector:withObject:afterDelay:, it does not leak.

A re-reading of the NSDistributedNotificationCenter does not highlight any obvious reason for this leak to happen.

Hi Stephane,

What's going on here is that the autoreleased objects in the distributed notification callback are being collected by the outermost autorelease pool, which is only drained when an event is received. If you add an autorelease pool to your callback, the "leak" disappears. Also, if you just do something in the app - say, open a menu - all the "leaked" memory is reclaimed.

So this isn't strictly a leak, but it's worth a bug report anyways. Please file one. Meanwhile, adding an autorelease pool to your notification callback is the best workaround.

Thanks!
-Peter

_______________________________________________

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


  • Follow-Ups:
    • [Worked around] Re: [NSImage initWithData]: Memory leak. Bug in code or in Framework?
      • From: Stéphane <email@hidden>
References: 
 >[NSImage initWithData]: Memory leak. Bug in code or in Framework? (From: Stéphane <email@hidden>)
 >[Worse] Re: [NSImage initWithData]: Memory leak. Bug in code or in Framework? (From: Stephane Sudre <email@hidden>)

  • Prev by Date: Re: Setting NSColorPanel to affect NSBackgroundColorAttributeName
  • Next by Date: Re: Is NSTableView sortDescriptors KVO compliant?
  • Previous by thread: Re: [Worse] Re: [NSImage initWithData]: Memory leak. Bug in code or in Framework?
  • Next by thread: [Worked around] Re: [NSImage initWithData]: Memory leak. Bug in code or in Framework?
  • Index(es):
    • Date
    • Thread