• 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
Where's the leak?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Where's the leak?


  • Subject: Where's the leak?
  • From: Scott Harper <email@hidden>
  • Date: Fri, 24 Mar 2006 19:05:25 -0700

Hello, I have written a very simple program to take a text file retrieved by typing the following into the shell, separating out the files names, and converting them all to PNG files. It's not meant to be a public program, so I've taken very little effort to verify that the files are in fact images or anything like that. Here's the shell command:

ls > list.txt

So it's a list of all files in the directory. Nice and simple. The code is attached at the bottom of this message, but the error I get is that more and more memory is being allocated to the program as it continues to run. Sounds like a memory leak, yes? Cool. We're on the same page. Problem is, I've gone through the code, and made sure that I release every object that I alloc; and I'm not retaining anything, and I STILL get a huge memory buildup.

Behold, the entirety of the code I wrote for the project (plus adding the method to a header file):

#import "GPController.h"

@implementation GPController

- (void)awakeFromNib {
int result;
NSString *path;
NSString *textFileData;
NSArray *fileTypes = [NSArray arrayWithObject:@"txt"];
NSOpenPanel *panel = [NSOpenPanel openPanel];

[panel setAllowsMultipleSelection:NO];
result = [panel runModalForDirectory:NSHomeDirectory() file:nil types:fileTypes];
if(result == NSOKButton) {
NSString *tempPath; //root directory reference
NSArray *fileList; //and array of all the strings for files
NSFileManager *fMan; //used exclusively for creating the output directory
NSImage *base = [[NSImage alloc] initWithSize:NSMakeSize(160, 160)];

path = [panel filename];
tempPath = [path stringByDeletingLastPathComponent];
textFileData = [NSString stringWithContentsOfFile:path];
fileList = [textFileData componentsSeparatedByString:@"\n"];
fMan = [NSFileManager defaultManager];
[fMan createDirectoryAtPath:[tempPath stringByAppendingString:@"/ converted/"] attributes:nil];

unsigned i, total;
total = 0;

for(i=0; i<[fileList count]; i++) {
total++;

[self writeNewFileFromSource:[fileList objectAtIndex:i] atLocation:tempPath withAidImage:base];

if((total % 250) == 0)
NSLog(@"Total thus far: %i", total);
}
[base release];
NSLog(@"Total number of items: %i", [fileList count]);
}
}


- (void)writeNewFileFromSource:(NSString *)src atLocation:(NSString *) loc withAidImage:(NSImage *)base {
NSRect fullRect = NSMakeRect(0, 0, 160, 160);
NSString *vTemp, *newPath;
NSData *pngData;
NSSize sourceSize;
NSPoint placePoint;
//Read image

vTemp = [loc stringByAppendingPathComponent:src]; //location of file tp be converted
newPath = [loc stringByAppendingString:[@"/converted/" stringByAppendingString:src]];
//Write image
NSImage* source = [[NSImage alloc] initWithContentsOfFile:vTemp];

sourceSize = [source size];
placePoint = NSMakePoint(80 - sourceSize.width/2, 80 - sourceSize.height/2);

[base lockFocus];
[[NSColor whiteColor] set];
NSRectFill(fullRect);
[source compositeToPoint:placePoint operation:NSCompositeCopy fraction:1.0];
NSBitmapImageRep *bitRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect(0, 0, 160, 160)];
[base unlockFocus];

pngData = [bitRep representationUsingType:NSPNGFileType properties:nil];
[pngData writeToFile:[newPath stringByAppendingPathExtension:@"png"] atomically:YES];
//Remove image??
[source release];
[bitRep release];
}


@end

I've also tried the ObjectAlloc.app, and I can't seem to figure out where/what the leak is. (Some generic name was getting basically all of the excess memory, and I'm not sure how to interpret the colors of lines, etc...) I also ran MallocDebug, but couldn't find anything terribly useful. Both of these if probably my own fault and inexperience, but as the only way to gain good experience is to do something right, I ask for your help in this.

--Scott
_______________________________________________
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


  • Follow-Ups:
    • Re: Where's the leak?
      • From: Jed Soane <email@hidden>
  • Prev by Date: Re: Separate string/file into "words"
  • Next by Date: Re: Where's the leak?
  • Previous by thread: Re: Cocoa Application Server
  • Next by thread: Re: Where's the leak?
  • Index(es):
    • Date
    • Thread