Hi Ken,
This code by itself should not be causing a leak. Couple of questions:
1. How do you know you have a memory leak? Sound like a silly question but
you didn't tell us anything about what you are using to detect leaks.
2. Who is calling this code, how many times? If you are passing the image to
something else in the sections you have commented out and you are calling this
many times, your memory usage may grow senza any cache'ing that maybe happening.
I would suggest putting a NSLog statement at the beginning and look at your
output window to make sure the code is not called more than you think.
-Tony Romano
On May 31, 2010, at 6:41 PM, Ken Tozier wrote:
> Hi
>
> I'm trying to write a thumbnailer class that takes a path to a photo and
> creates a thumbnail at a user specified size. The code creates the thumbnails
> OK, but there's this monster memory leak, to the tune of about 100 MB every
> 3-4 seconds, that seems to be related to NSImage.
>
> What's happening is that if I comment out the line that initializes a new
> image, the memory leak disappears. I've tried forcibly releasing the images,
> tried autoreleasing them, tried creating a fixed size buffer into which all
> the images are read, nothing seems to work.
>
> I'm using garbage collection, so that along with the deliberate releasing of
> the images, makes me wonder why the collector isn't getting the hint, that
> it's ok to release the memory for these photos. Could someone point out what
> I'm doing in the following code that prevents the images from getting
> released?
>
> Thanks for any help
>
> - (NSString *) createJPEGThumbnail:(NSString *) inPath
> site:(NSString *) inSite
> {
> NSDictionary *siteRecord,
> *pubRecord;
>
> NSString *sourceName =
> [inPath lastPathComponent],
> *sourceRoot
> = [sourceName stringByDeletingPathExtension],
> *destName
> = [[sourceRoot stringByAddingPercentEscapesUsingEncoding:
> NSUTF8StringEncoding] stringByAppendingPathExtension: @"jpg"],
> *pubCode
> = [self pubCodeFromPath: inPath],
> *thumbPath;
>
> NSFileManager *manager =
> [NSFileManager defaultManager];
>
> siteRecord = [thumbDirectories
> objectForKey: inSite];
> pubRecord = [[siteRecord objectForKey:
> @"publications"] objectForKey: pubCode];
>
> if (pubRecord == nil)
> pubRecord = [[siteRecord objectForKey:
> @"publications"] objectForKey: @"~MISCELLANEOUS"];
>
> thumbPath = [[pubRecord objectForKey:
> @"thumb_path"] stringByAppendingPathComponent: destName];
>
> if (![manager fileExistsAtPath: thumbPath])
> {
> // I've tried both of these, didn't make the slightest
> difference.
> // Both leaked memory at a furious pace
>
> // Option 1:
> NSImage *image
> = [[[NSImage alloc] initWithContentsOfFile: inPath] autorelease];
>
> /* do some stuff */
>
>
> // Option 2
> NSImage *image
> = [[NSImage alloc] initWithContentsOfFile: inPath];
>
> /* do some stuff */
>
> [image release];
> }
>
> // make sure it worked
> if ([manager fileExistsAtPath: thumbPath])
> return thumbPath;
> else
> return nil;
> }
> _______________________________________________
>
> Cocoa-dev mailing list ([email protected])
>
> 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/tonyrom%40hotmail.com
>
> This email sent to [email protected]
>
-Tony
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]