Re: Leak in NSData +dataWithContentsOfURL:
Re: Leak in NSData +dataWithContentsOfURL:
- Subject: Re: Leak in NSData +dataWithContentsOfURL:
- From: email@hidden
- Date: Fri, 15 Mar 2002 18:12:51 -0800
I finally managed to chase down the memory leak in my app. I believe
that the NSData class method dataWithContentsOfURL:(NSURL *)url leaks
memory. I have hacked up a quick demo, which you'll find at
http://MrFeinberg.com/leak.html
The bottom line is that the method allocates memory when constructing
the NSData object, but the memory is not released when the NSData is
released.
Actually, this doesn't appear to be the problem as far as I can tell.
Using OmniObjectMeter 2.0 (which is soon to go into beta! :), it looks
like the problem is that -[NSHTTPURLHandle dealloc] is busted.
...
The owning NSHTTPURLHandle experiences the following three events.
First it is allocated, then autoreleased and finally the
NSAutoreleasePool releases it. OmniObjectMeter is claiming that the
NSHTTPURLHandle isn't getting deallocated though. This is a symptom of
not calling [super dealloc] in your -dealloc implementation.
So, based on this I would say that -[NSHTTPURLHandle dealloc] has two
bugs:
- It isn't releasing an NSData ivar.
- It isn't calling [super dealloc].
This is all very interesting. However, I wonder if it's right beyond
a doubt. The problem is that NSURLHandle defines "caching" behavior
whereby URLHandles, and the data they have fetched, get retained so that
subsequent uses of the handle don't cause a refetch. It sounds to me
like the NSHTTPURLHandle is probably being placed into that cache, which
is retaining it. You may not be seeing that retain in OmniObjectMeter
because perhaps it is being done using CF, or even by more directly
manipulating the retain count (shudder). Have you confirmed that
-dealloc is getting called on the NSHTTPURLHandle at all, using a
breakpoint? Have you printed out what the handle thinks its retain
count is, at various interesting points in time?
Sorry if I'm barking up the wrong tree and this is actually a bug in
Apple's code, but the evidence presented so far seems less than
conclusive to me...
Ben Haller
Stick Software
_______________________________________________
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.