On Tue, Jun 2, 2009 at 7:57 AM, Shawn Erickson <shaw...@gmail.com> wrote:

> On Tue, Jun 2, 2009 at 12:12 AM, Graham Cox <graham....@bigpond.com>
> wrote:
> >
> > On 02/06/2009, at 4:23 PM, Trygve Inda wrote:
>
> >> The file that this image comes from will be deleted later on, but once
> >> initWithContentsOfFile is called, I assume it no longer needs the file,
> >> right?
>
> No it might still need the file. NSImage is often lazy about what it
> does so as to not waste resources until they are needed. Can you
> outline what you are doing with the file after you create the NSImage
> instance? Are you writing to it again, etc.?


This is the difference between -initByReferencingURL: and
-initWithContentsOfURL:.

The "contents" methods non-lazily suck the data in from disk and
disassociate from the file.

The "referencing" methods, on the other hand, treat the in-memory
representation as a cache for the file on disk.  When you use this method,
you promise that the file on disk is not going anywhere or changing.  It's
easy to make this promise for files that are in your app's bundle and are
used for its UI.  +[NSImage imageNamed:] uses -initByReferencingURL:.

-initByReferencingURL: does no IO.

-Ken
Cocoa Frameworks
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to