• 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: Image loading bug out of nowhere...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Image loading bug out of nowhere...


  • Subject: Re: Image loading bug out of nowhere...
  • From: Michael Becker <email@hidden>
  • Date: Thu, 3 Nov 2005 17:37:52 +0100

Am 03.11.2005 um 15:59 schrieb glenn andreas:
Based on this snippet of code, you're not closing the file that was opened when you did [[NSData alloc] initWithContentsOfFile: thumbnailPath]. Do you have [imageData release]?

Also note, after fixing that, that the [NSBitmapImageRep imageRepWithContentsOfFile: thumbnailPath] also will open the file, and since you retain it and never release it, it will also leak a file descriptor.

Actually, a little further down in my code, I release both imageData and bitmapImageRep. They both still remain autoreleased though.


More subtly, once you fix that, imageRepWithContentsOfFile is autoreleased, and won't actually be released until the next main event loop is run, so if this code is inside a large loop (like iterating through thousands of files), you'll want to add an autorelease pool that your periodically empty explicitly...

Is there a general recommendation how to work with such things? So I create my imageData and my bitmapImageRep, use them, release them and that's it? Will the file descriptor be released this way? Will my problems go away if I do this:


for (i=0; i<imagesCount; i++) {

NSData *imageData = [[NSData alloc] initWithContentsOfFile: thumbnailPath];
NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithData:imageData];


    [imageList setObject:imageRep forKey:thumbnailPath];

    [imageData release];
    [imageRep release];
}

Will this work as I am explicitely alloc'ing and release'ing the objects? Will putting them into the dictionary (imageList) have any negative effects?

Regards,
Michael

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Image loading bug out of nowhere... (From: Michael Becker <email@hidden>)
 >Re: Image loading bug out of nowhere... (From: glenn andreas <email@hidden>)

  • Prev by Date: Cocoa Developer wanted in Pittsburgh
  • Next by Date: Re: Problems with Attributed Strings and NSTextField
  • Previous by thread: Re: Image loading bug out of nowhere...
  • Next by thread: Reviews of "Advanced Mac OS X Programming"
  • Index(es):
    • Date
    • Thread