Re: ImageNamed not refreshing
Re: ImageNamed not refreshing
- Subject: Re: ImageNamed not refreshing
- From: Brock Brandenberg <email@hidden>
- Date: Mon, 30 Sep 2002 16:45:18 -0500
Hi Joe.
Sorry, but I meant to write earlier on this one. You've already figured out
a good work around, though.
>
The magic seems to be to use a COPY of the imageNamed when calling setImage.
>
>
NSImage *theImage = [[NSImage imageNamed:@"picture.tiff"] copy];
>
>
What seems to have been happening was the picture.tiff itself was being
>
"edited" by the image editing function. By using a COPY instead, the problem
>
is solved. Hopefully this will help others.
Since imageNamed: is a class method, each time you call it you are getting
the same, single instance that it has already loaded from the file. Even if
you alter the data that the object points to, the object pointer itself
remains the same, so when you call the method again, you get a pointer to
the same object and data that you already have.
You could release the class object and acquire it again, but this can be
risky. Note the docs: "The image returned by this method should not be
freed, unless it's certain that no other objects reference it." If you free
it, it should reload the file data again and give you a new object pointer.
But, your copy method is a safer and cleaner solution. Just make sure you
release the old one when you're done with it. Don't just reassign the
pointer to a new copy or you'll have a memory leak.
Brock Brandenberg
----- industrial design @ www.bergdesign.com ------
_______________________________________________
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.