• 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: NSURLConnection leaking on multi-threaded apps?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURLConnection leaking on multi-threaded apps?


  • Subject: Re: NSURLConnection leaking on multi-threaded apps?
  • From: Paul Borokhov <email@hidden>
  • Date: Tue, 13 Mar 2007 20:42:26 -0700

Thanks for the tip, but unfortunately it didn't help in this case. By the way, I am now using NSURLConnections directly, rather than NSXMLDoc initWithContents... here's the code:
-(NSData *)fetchXMLData:(NSURL *)theURL {
	NSURLRequest *urlRequest = [NSURLRequest requestWithURL:theURL  cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:[self connectionTimeoutInterval]];
	NSHTTPURLResponse *xmlResponse;
	NSError *fetchError;
	NSData *xmlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&xmlResponse error:&fetchError];
	return xmlData;
}
Adding the NSURLCache calls didn't help, though I would expect that since the NSURLRequest already has a cachePolicy of NSURLRequestReloadIgnoringCacheData.
Anyone have any more info on this? Christ..
Paul

----------Original Message----------
  On 3/13/07 14:07 , John Mikros (email@hidden) wrote:
> I don't know if this will help you, but our app was leaking memory in
> NSURLConnection as well.  I didn't realize it could be related to
> creating the NSURLConnection on a secondary thread -- that may very
> well be the case.
>
> In any event, we found that the leak went away if we set the capacity
> of the URL cache to zero.
>
> 	[[NSURLCache sharedURLCache] setMemoryCapacity:0];
> 	[[NSURLCache sharedURLCache] setDiskCapacity:0];
>
> In our case, we don't want any of the data cached anyway, so this
> made sense.
>
> -john
>
> On Mar 11, 2007, at 9:12 AM, Matt Neuburg wrote:
>
>> On Sun, 4 Mar 2007 15:51:06 -0800, Paul Borokhov <email@hidden> said:
>>> So, as a follow-up to my previous threads discussion, which I do
>>> want to keep
>>> on-topic, it appears that NSURLConnection leaks whenever it's
>>> called inside a
>>> method that's been detached from the main thread. Namely, I tested my
>>> application with threading and without, and the thread-less version has no
>>> leaks. Just to reiterate, I never actually call the NSURLConnection
>>> methods
>>> directly, I DO have autorelease pools set up properly, and there is
>>> NOTHING
>>> else that is leaking (apart from the NSUC-associated classes), even
>>> though I
>>> do create (and manage to properly discard) a lot of other data,
>>> including XML
>>> documents, strings, etc. I'm guessing that the reason NSURLConnection gets
>>> called at all is because I call NSXMLDocument
>>> initWithContentsOfURL:options:error: to get data, and that method uses
>>> NSURLConnection internally?
>>
>> This sounds like a variant of the NSURLConnection bug that causes a
>> sporadic
>> crash when loading Core Data data from an XML store. The
>> NSPersistentStoreCoordinator calls NSXMLDocument
>> initWithContentsOfURL:options:error: which calls NSURLConnection and things
>> rapidly go south because of threading (and it's all Apple's code, so doing
>> something about it is quite tricky).
>>
>> So, to sum up, yes, it's known that there are memory-management problems
>> with NSURLConnection and threads, and Apple's own code falls prey to these
>> problems. m.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: NSURLConnection leaking on multi-threaded apps? (From: Matt Neuburg <email@hidden>)
 >Re: NSURLConnection leaking on multi-threaded apps? (From: John Mikros <email@hidden>)

  • Prev by Date: Re: Bonjour and multi-meg files
  • Next by Date: Re: NSRecentDocumentRecords - dynamically updating
  • Previous by thread: Re: NSURLConnection leaking on multi-threaded apps?
  • Next by thread: Problem with NSArchiver in document-based application
  • Index(es):
    • Date
    • Thread