• 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 failing [SOLVED]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSURLConnection failing [SOLVED]


  • Subject: Re: NSURLConnection failing [SOLVED]
  • From: Antonio Nunes <email@hidden>
  • Date: Thu, 20 Mar 2008 11:03:24 +0000

On Feb 26, 2008, at 9:14 PM, Nir Soffer wrote:

Turns out garbage collection was doing me in.  When the
NSURLConnection object was hanging out waiting for a response, it
would get collected.  To work around this, after creating the
NSURLConnection object I just stick it in a NSMutableSet.  When the
delegate gets the -connectionDidFinishLoading: message I remove the
connection object from the set.  Works great now.

Any object you create on the stack will be gone when the method is finished :-)


You must keep a reference to the connection.

Or how about turning off garbage collection temporarily for the object? Something like:


Create the connection and make sure it sticks around:

theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[[NSGarbageCollector defaultCollector] disableCollectorForPointer:theConnection];



Clean up when done:

- (void)connection:(NSURLConnection *)connection didFailWithError: (NSError *)error
{
[...do your processing...]
[[NSGarbageCollector defaultCollector] enableCollectorForPointer:connection];
}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[...do your processing...]
[[NSGarbageCollector defaultCollector] enableCollectorForPointer:connection];
}


This seems like less hassle to me, but I don't know if it is good form. Is it really better keep a strong reference to the connection object, and if so, why?

António

-----------------------------------------
Perfume is the forgiveness
that the trampled flower casts
upon the heel that crushes it.
-----------------------------------------



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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


  • Prev by Date: Re: Web Core Service and SSL problem
  • Next by Date: Cannot remove an observer
  • Previous by thread: Re: Web Core Service and SSL problem
  • Next by thread: Cannot remove an observer
  • Index(es):
    • Date
    • Thread