Re: Image loading bug out of nowhere...
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