0

I'm having a baffling leak. LEAKS tells me that the line indicated below is leaking. I'm paraphrasing, but faithfully. It pulls an NSDictionary from a file, then sends it off to another process.
As far as I know, the memory for all of these objects should be managed by the OS.

I don't know how LEAKS works, but I'm guessing it's marking the point where the OS wants to release "statusdict" but can't because there's something unlereased within it. But there's nothing in it that wasn't acquired by the process shown here.


NSDictionary *statusdict = [self readStatus];

[self runProcess:[statusdict objectForKey:@"objectname"]];  <- it leaks here


-(NSDictionary*) readStatus {

    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSString *status = [[docPath stringByAppendingPathComponent:@"status.plist"] retain];

    cstat = [NSDictionary dictionaryWithContentsOfFile:status];

    [status release];


    return (cstat);

}
Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
adamD
  • 125
  • 2
  • Include the `runProcess` method. – Deepak Danduprolu Jun 09 '11 at 04:00
  • What Deepak is getting at is, if runProcess retains dictionary and never autoreleases or releases it, then that is the leak. –  Jun 09 '11 at 04:04
  • ah. this must be it. the runProcess method copies the string (just the string, not the whole dict, is passed) to another string that is permanently retained. so the line is just self.keepME = passedValue. – adamD Jun 09 '11 at 15:38
  • but wait. Is it possible that the leak in runProcess has nothing to do with the dictionary or its contents (one of which is passed in)? Would ANY leak that takes place in that method cause the line that calls it to be highlighted in LEAKS? I addressed what I thought was the problem here by changing self.keepME to an NSMutableString and using setString to alter its contents, so the object that is actually passed in to runProcess is NOT retained by me. But LEAKS still says I have a leak. – adamD Jun 09 '11 at 19:19
  • I've been drilling down on this. It has nothing to do with the code shown, as you guys have noted. Thanks for pointing that out. I'm going to start it as a new question to get a clean slate, since I still can't find the answer. – adamD Jun 10 '11 at 02:59
  • http://stackoverflow.com/questions/6301648/memory-leak-that-appears-to-be-in-touchjson, if anyone is interested – adamD Jun 10 '11 at 03:29

1 Answers1

0

A leak occurs when an object is retained more than it's released. The system doesn't automatically release of anything. You either release it manually, or autorelease it.

I can't tell where your leak is from this code, though my guess is the runProcess method.

But finding this leak won't solve your problem. You need to understand iOS memory management.

Start here:

Steven Fisher
  • 44,462
  • 20
  • 138
  • 192