• 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
Monster memory leak and I can't figure out why
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Monster memory leak and I can't figure out why


  • Subject: Monster memory leak and I can't figure out why
  • From: Ken Tozier <email@hidden>
  • Date: Mon, 31 May 2010 21:41:05 -0400

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@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Monster memory leak and I can't figure out why
      • From: Tony Romano <email@hidden>
    • Re: Monster memory leak and I can't figure out why
      • From: Jens Alfke <email@hidden>
    • Re: Monster memory leak and I can't figure out why
      • From: "email@hidden" <email@hidden>
  • Prev by Date: I need float resolution bitmap data from a JPG using CIImage or similar helper
  • Next by Date: Re: Stealing settings from Mail.app
  • Previous by thread: Re: I need float resolution bitmap data from a JPG using CIImage or similar helper
  • Next by thread: Re: Monster memory leak and I can't figure out why
  • Index(es):
    • Date
    • Thread