Re: Threads again: NSData leaking (using dataWithContentsOfURL) [bug verified]
Re: Threads again: NSData leaking (using dataWithContentsOfURL) [bug verified]
- Subject: Re: Threads again: NSData leaking (using dataWithContentsOfURL) [bug verified]
- From: Stefan Pantke <email@hidden>
- Date: Wed, 11 Feb 2004 01:32:53 +0100
I verified the problem using some lines of code:
Even this small example code consumes memory:
>>>
- (IBAction)runTheTest:(id)sender
{
int n;
NSURL *urlForDownload;
NSData *downlaodedData;
for( n=0; n<10; n++ ) {
urlForDownload = [NSURL URLWithString:@"<SomeURLHere>"]; // may
return nil
downlaodedData = [NSData dataWithContentsOfURL:urlForDownload];
}
}
<<<
At least leaks reports an ever growing number of allocated nodes, if I
press several time the related action button, and thus fire the method.
At start:
>>>
[sys:~] sp% leaks NSDataTest | head
Process 13912: 10649 nodes malloced for 810 KB
Process 13912: 3 leaks for 256 total leaked bytes.
<<<
After some method calls:
>>>
[sys:~] sp% leaks NSDataTest | head
Process 13867: 18765 nodes malloced for 2587 KB
Process 13867: 7 leaks for 1456 total leaked bytes.
<<<
Am 10.02.2004 um 15:54 schrieb BOGUS BOGUS:
On Feb 10, 2004, at 1:38 AM, Stefan Pantke wrote:
In Apple's OS X 10.2 release notes, I found some hints on
NSData fixed leaks/problems.
Since I work on 10.3.2, things should work fine.
Any help greatly welcome.
Am 09.02.2004 um 20:51 schrieb Stefan Pantke:
As soon as I perform
downloadedData = [NSData
dataWithContentsOfURL:urlForDownload];
all workers mutate to memory consumers - the node count reported
from leaks
jumps from 20000 to 88000.
Since URLWithString is a convenience method, it should autorelease
it's memory.
Thus, it SHOULD be released, since the worker's main loop releases
it's local
AutoreleasePool at the end of the loop, which has been allocated at
the beginning
of the loop.
This assumption may be the problem. I think the autorelease pool is
cleaned up only if a UI event is processed by the runloop. Try posting
an event periodically in your thread and see if it fixes the problem.
The downloadedData is not used by any other part of code, not is it
used for
diplay purposes, e.g.
Baskaran Subramaniam
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.