views:

340

answers:

1

I have been living on Instruments for last few hours staring at a puzzling memory leak. I have isolated it to this single line of code in an NSOperation subclass I wrote:

NSData *myData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myURLString]];

Periodically this will leak 3500 bytes. Is anyone else seeing this? If so, is there a work around?

Thanks in advance.

UPDATE:

Here is the relevant section of code within the main() body of my NSOperation subclass:

- (void)main {

// ...

NSData *sequenceData = 
[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:concatenatedURLString]];

NSString *sequenceString = 
[[NSString alloc] initWithBytes:[sequenceData bytes] length:[sequenceData length] encoding:NSUTF8StringEncoding];

NSDictionary *result = [NSDictionary dictionaryWithObjectsAndKeys:
self.chromosome, @"chromosome",
[NSNumber numberWithInt:self.basepairStart], @"basepairStart", 
[NSNumber numberWithInt:self.basepairEnd], @"basepairEnd", 
sequenceData, @"sequenceData", 
sequenceString,  @"sequenceString", 
nil];

[sequenceData   release];
[sequenceString release];

[self.target performSelectorOnMainThread:self.action withObject:result waitUntilDone:NO];


}

As you can see sequenceData and sequenceString are properly released. Also, I have confirmed that all ivars of this subclass (chromosome. etc.) are properly memory managed.

-Doug

A: 

You have to release or autorelease myData, otherwise it will leak according to the Cocoa Memory Management Rules

nall
Just added the relevant code showing proper releasing of the NSData instance.
dugla