views:

455

answers:

1

I'm getting an instruments Memory Leak with this iPhone 3.0 SDK code.

I'm using the JSON from http://code.google.com/p/json-framework/

Here is my code:

// .h
@property (nontatomic,retain) NSMutableArray *tweets;


// .m
import" JSON.h"
@synthesize tweets;
...
    tweets = [[NSMutableArray alloc] init];

    NSURL *url = [NSURL URLWithString:@"http://www.someurl.com"];
    NSString *jsonString = [NSString stringWithContentsOfURL:url];
    NSArray *results = [jsonString JSONValue];
    NSArray *data = [results valueForKey:@"stories"];

    for(NSDictionary *tweet in data) {
     TweetmemeData *tweetmeme = [[TweetmemeData alloc] initWithTweet:tweet];
     [tweets addObject:tweetmeme];
     [self debugDump:tweetmeme];
     [tweetmeme release];
    }
    [results release];

    return tweets;

If possible, please explain more about this form of memory management. I'm very familiar with retain/release but obviously am having trouble implementing it :)

Thanks!

+1  A: 

It's worth noting that many leaks that will come up in the simulator don't happen at all on the hardware. Are you using the simulator or testing it on the phone?

Sneakyness
Hi! Thanks for the info. I am using the Simulator.. will check the device.Notice that I am NOT releasing the NSArray *data ... if I do I get a lockup. Also, if I RETAIN results it seems to help...thanks in advance
Phil Wright
You should read up on Memory Management, here's Apple's official guide: http://developer.apple.com/iPhone/library/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html and here is another pretty good article I found: http://akosma.com/2009/01/28/10-iphone-memory-management-tips/
Sneakyness