• 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
Memory management about async object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory management about async object


  • Subject: Memory management about async object
  • From: ico <email@hidden>
  • Date: Tue, 28 Dec 2010 14:18:42 +0800

Hi,

I am working on an app that will asynchronous to load data. Suppose I have a
view controller with a method:

in MyViewController:

- (void) loadData {
    DataHandler *myHandler = [[DataHandler alloc] init];
    // set this view controller itself as a delegate, when the data loading
finished, myHandler will call its callback method
    myHandler.delegate = self;
    [myHandler startAsyncLoading];
}

// callback method get called by DataHandler when the data loading is done

- (void) myCallback:(id)responseData {
    // setup the data source to be used later
}

In the DataHandler class, it will use NSURLConnection to call a webservice
to load the data asynchronous. And
it has a delegate instance variable which points to the MyViewController,
when
connectionDidFinishLoading is called, I will do like this:

- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
    // do something
    [delegate myCallback:self];
    // point 1
}

My question is, when should I release the myHandler? Should I release it in
the myCallback, but after
myCallback method finishes, it will return point 1 indicated as above, and
that myHandler instance is just
released.

Or there is a better way to deal with async object? I also wonder how
NSURLConnection class handle this itself.

Thanks.

--
==========================
Life isn't about finding yourself.
Life is about creating yourself.
_______________________________________________

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

  • Follow-Ups:
    • Re: Memory management about async object
      • From: James Bucanek <email@hidden>
    • Re: Memory management about async object
      • From: "Stephen J. Butler" <email@hidden>
  • Prev by Date: Re: Drawing to two CALayers at once (or pretend to)?
  • Next by Date: Re: Memory management about async object
  • Previous by thread: Re: Drawing to two CALayers at once (or pretend to)?
  • Next by thread: Re: Memory management about async object
  • Index(es):
    • Date
    • Thread