Leak in URL loading system (ctnd.)
Leak in URL loading system (ctnd.)
- Subject: Leak in URL loading system (ctnd.)
- From: Stefan Pantke <email@hidden>
- Date: Wed, 11 Feb 2004 16:00:47 +0100
lance,
thanks for you information!
Yes, a button press allocates node. But I marked in ObjectAlloc after
one button press, then did several other presses - while downloading -
and then there are NSUrl* obects allocated, which I didn't retained.
Please have a look at the line marked: 11-Feb-2004 05:06 .
Something else: If download is performed asynchronously and the
the NSURLDownload objects are released in the delegates objects,
everything is fine. No extra objects allocated.
If download is performed synchronously, a huge number of
NSURLConnectionCallbackData
is allocated and - as far as I see - not released.
The number is ever growing, around the same number of
NSURLConnectionCallbackData each call.
And furthermore, several other objects which node counts are multiplies
of NSURLConnectionCallbackData.
I suppose dataWithContentsOfURL calls sendSynchronousRequest and
leaking in this situation is quite reasonable.
If might be wrong, but i _feel_ this is a serious bug in the URL system.
I suppose, that the spawned threads hold local retained copies of the
downloaded
data . But only, if the synchronous calls are performed. Probably, they
do
not release the returned Download or Connection objects in their
delegates
methods.
If you have any insights, please contact me again! I would be happy to
solve this problem.
>>>
09-Feb-2004 09:36 PM stefan Pantke:
* SUMMARY
Used in an application, that uses different worker threads to download
stuff,
[NSData dataWithContentsOfURL:urlForDownload]
consumes memory and seems not beeing released. The amount of space is in
the size of retrieved data.
* STEPS TO REPRODUCE
1. Setup an XCode project
2. create some worker trhreads using NSThread
3. Fire some calls of [NSData dataWithContentsOfURL:urlForDownload] in
each thread
* RESULTS
Memory is not released
* REGRESSION
-
* NOTES
Each NSThread uses it's own AutoreleasePool.
Furthermore, the main worker's loop, creates an AutoreleasePool and
releases it
at the end of the worker's loop.
11-Feb-2004 01:29 AM stefan Pantke:
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:
>>>
[sp:~] 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:
>>>
[sp:~] sp% leaks NSDataTest | head
Process 13867: 18765 nodes malloced for 2587 KB
Process 13867: 7 leaks for 1456 total leaked bytes.
<<<
11-Feb-2004 05:06 AM stefan Pantke:
Using now
downloadedData = [NSURLConnection
sendSynchronousRequest:urlRequest
returningResponse:&aResponse
error:&anError];
i figured out using ObjectAlloc, that after around 1200 calls, there
are 1179 NSURLConnectionCallbackData nodes in memory. And several other
objects, which
are roughly muliplies of the NSURLConnectionData count. But no NSData
or CFData objests.
May the URL Loading system leak indeed?
How do I then dispose of these extra objects?
<<<
Am 11.02.2004 um 14:18 schrieb lbland:
hi-
what does this give:
- (IBAction)runTheTest:(id)sender
{
int n;
NSURL *urlForDownload;
NSData *downlaodedData;
NSAutoreleasePool pool = [[NSAutoreleasePool alloc] init];
for( n=0; n<10; n++ ) {
urlForDownload = [NSURL URLWithString:@"<SomeURLHere>"]; // may
return nil
downlaodedData = [NSData dataWithContentsOfURL:urlForDownload];
}
[pool release];
}
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.
by pressing the button you can bring in memory (for the button). not
all memory has to do with the action.
good luck!-
-lance
_______________________________________________
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.