Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 799755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:10:54+00:00 2026-05-14T23:10:54+00:00

Inspired by Apple’s LazyTables sample, I’ve just built myself a class called ImageLoader. It’s

  • 0

Inspired by Apple’s LazyTables sample, I’ve just built myself a class called ImageLoader. It’s agonizingly clever of me. And as is often the case when I’m agonizingly clever, I’m up against the limits of my wisdom about how to handle the memory of this object.

The thing gets instantiated from a UIViewController subclass inside viewDidLoad, thusly:

ImageDownloader *downloader = [[ImageDownloader alloc] init];
[downloader startDownloadWithImageView:self.theImageView
                           andImageURL:[NSURL URLWithString:myUrlString]];

Inside that method in ImageDownloader, I go:

-(void)startDownloadWithImageView:(UIImageView *)imageView
                      andImageURL:(NSURL *)url
{
 self.theImageView = imageView;
 [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
 self.activeDownload = [NSMutableData data];

 NSURLConnection *conn = [[NSURLConnection alloc]
  initWithRequest:[NSURLRequest requestWithURL:url] delegate:self];
 self.imageConnection = conn;
 [conn release];
}

and my delegate method as a NSURLConnectionDelegate is (in pertinent part):

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{  
 UIImage *image = [[UIImage alloc] initWithData:self.activeDownload];
 theImageView.image = image;
 [image release];
}

There’s obviously all kinds of error checking it doesn’t do yet, but you get the brilliance of it, right? I can now pass this thing a UIImageView and a NSURL and let it lazy-load the image asynchronously. Sa-weet!

So here’s the question… How do I release downloader? I don’t think I can autorelease from the ViewController where I create it, because I wouldn’t expect NSURLConnection to call its delegate by the end of the run loop. Can I release self at the end of connectionDidFinishLoading? I’ve never seen that done, feels a little weird to release myself inside a method of myself.

My other thought is, I could make this a singleton and just not be concerned about it sticking around until we terminate. But I’d rather have the object come to life and go away cleanly.

Incidentally, the next step of my cleverness will be to add this functionality as a category of UIImageView. It’d be kind of neat to call [imageView asynchronouslyLoadImageFromURL:(NSURL *)url].

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:10:55+00:00Added an answer on May 14, 2026 at 11:10 pm

    You could always put a [self retain] in the -startDownloadWithImageView:andImageURL: method and a [self release] in the -connectionDidFinishLoading: method. It’s unconventional, obviously, but that would allow you to autorelease it after creating it without worrying about it being killed prematurely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.