• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Leak in NSData +dataWithContentsOfURL:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Leak in NSData +dataWithContentsOfURL:


  • Subject: Re: Leak in NSData +dataWithContentsOfURL:
  • From: email@hidden
  • Date: Fri, 15 Mar 2002 21:26:31 -0800

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.

But if you (the user) are not explicitly retaining an NSURLHandle--indeed, if you are explicitly releasing or autoreleasing an NSData--then the library has no business retaining anything. Furthermore, if you fetch the same URL more than one time via dataWithContentsOfURL, you will clearly see the network being hit each time. Furtherfurthermore, if there were some cache being invoked, there would be no need to allocate still more memory each time.

If you create an object and dispose of it properly, the memory should go back to the heap.

I'm not really inclined to defend NSURLHandle's design or behavior. :-> However, I do believe I have seen it cache data correctly and not hit the network a second time.
And the statement "if you (the user) are not explicitly retaining...then the library has no business retaining anything" seems quite silly to me. Lots of code, in Cocoa and other libraries, caches for the user; this is generally considered to be a Good Thing, which is why all us programmers spend so much time and effort writing the code to do it. :-> If Cocoa classes didn't cache things for the user, you would be amazed how much worse performance would be. Most of the time, the user is given no control over that caching with any APIs.

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.

References: 
 >Re: Leak in NSData +dataWithContentsOfURL: (From: Jonathan Feinberg <email@hidden>)

  • Prev by Date: Re: Utility window to minimize
  • Next by Date: Re: Yet another NSOutlineView question...
  • Previous by thread: Re: Leak in NSData +dataWithContentsOfURL:
  • Next by thread: Help! with NSFileManager's currentDirectoryPath
  • Index(es):
    • Date
    • Thread