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

  • SEARCH
  • Home
  • 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 8742763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:33:23+00:00 2026-06-13T11:33:23+00:00

first of all, I am not using ARC as I had even bigger problems

  • 0

first of all, I am not using ARC as I had even bigger problems with it and I need full control of my memory management.

Here is the situation: I need to load a lot of remote JPEG images from a server and display them in a scrollview. The top images in the scroll view get released once the user scrolls down a bit. That is working, the containing views are all released normally.
Problem is, that after loading the remote image, a lot of memory stays allocated and doesn’t get released.
Here is my code to fetch the remote images(subclassing UIImageView):

- (void)downloadImage    {
    NSData *posterData = [[NSData alloc] initWithContentsOfURL:self.url options:NSDataReadingUncached error:nil];
    UIImage *img = [[UIImage alloc] initWithData:posterData];
    [posterData release];
    self.image = img;
    [img release];
}
// that gets called from:
- (void)setImageFromURL:(NSURL *)_url{
    [NSThread detachNewThreadSelector:@selector(downloadAndLoadImage) toTarget:self withObject:nil];
}

When I inspect my code with Instruments, my UIImageView gets released as intended, but the following still stucks in my memory and spams it:
Instruments

Apparently CFData, Malloc 9.00 KB, NSConcreteData are all resulting from my downloadImage method.
What am I doing wrong? This is driving me crazy…how do you load a lot of remote images memory safe?
I also tried NSURLConnection, but it was rather worse then better. 🙁

Image size varies from 6 to 25KB.

Many thanks in advance!

UPDATE

I ended up using SDWebImage which works great and is very easy to use.

  • 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-06-13T11:33:24+00:00Added an answer on June 13, 2026 at 11:33 am

    Is image downloading on a background thread? If yes then where is NSAutoreleasePool? You have to add:

    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    
    // your downloading thread code here
    
    [pool release];
    

    Or for ARC:

    @autoreleasepool {

        // your downloading thread code here
    

    }

    Also if image download happens on a background thread you cannot do self.image = img; you should call it on the main thread, because UI elements should be modified only from the main thread:

    [self performSelectorOnMainThread:@selector(setImage:) withObject:img waitUntilDone:YES];
    

    Actually SDWebImage library does everything for you, and has memcache and disk cache

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

Sidebar

Related Questions

First of all I'm not sure this is even possible, however I need to
First of all, I'd like to say I'm not using any off-line feature from
First of all, I am using XCode 4.2 and I am not using storyboards.
First of all I'm not interested of using some jquery plugin . I just
First of all I am making it clear that, I am not using any
First of all, we're not using the Web Application project, we're using the Web
First of all: I am not able to find out the proper Title of
first of all: this is not the same as this . The ModelBackend has
First of all I am not a designer. so this question is may be
First of all I'm not sure if .exe window is the proper term. It's

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.