Re: Non-retained NSImages still available?
Re: Non-retained NSImages still available?
- Subject: Re: Non-retained NSImages still available?
- From: "Adam R. Maxwell" <email@hidden>
- Date: Fri, 4 Apr 2008 19:18:35 -0700
On Apr 4, 2008, at 6:43 PM, stephen joseph butler wrote:
On Fri, Apr 4, 2008 at 8:29 PM, Matt R <email@hidden> wrote:
imgArray[x] = [NSImage imageNamed:@"foo.jpg"];
Throughout the scope of my app, when the drawRect fires, these images
always
appear properly. But today I suddenly released that I never
retained them,
which has me kind of baffled. My understanding was that once the
method
that
creates the auto-released object exits, eventually that object will
be
released. Other objects, like NSStrings, which are created within
this
view's methods, seem to need to be retained as the view's methods
use the
object, but the NSImage array shows up without being retained. Can
someone
please help me understand why this is?
NSImage is caching them, and your app doesn't create enough images
to force
an eviction. But if you ever do end up evicting one of them, you'll
run into
problems (obviously).
Can you do that by creating too many images? The docs for
+imageNamed: say "...you do not need to retain the returned image
object unless its name could be cleared. You can clear an image object
from the table by passing nil to the setName: method of the
corresponding NSImage object."
So even though this should work correctly, I'd use an NSArray or
manually retain the images, though, just for consistency. Using C
arrays to hold objects is certainly useful at times, but can be a
dangerous practice IMO.
--
adam
_______________________________________________
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