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 1059589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:11:48+00:00 2026-05-16T18:11:48+00:00

I have this huge problem with memory management. The problem : I’ve got a

  • 0

I have this huge problem with memory management.

The problem:
I’ve got a UIScrollView, I’ve got an Array with 24 paths to Images in it and I want to show them in the UIScrollView with paging enabled.

All images is in the size 1024×748 (iPad landscape resolution with status bar) and the filetype is jpg or png.

I’m using lazy loading just to not exceed the memory when the viewDidLoad. And I’m going with the lazy load sample from Apple with the PageControl. Though I’m using UIImageViews instead of UIViews.

So my problem is that when I scroll to the third image, i want to remove the first image from the UIScrollView and release its memory. Because the further I scroll, more memory is draining. When I page in the UIScrollView and a new image is loaded and added, about 5000kb more memory is used, and when i step in to the unloadPage: (see below) nothing is released. Am I just “doing it wrong”?

How do I release and remove UIImageViews properly?

(I’m loading the UIImages with initWithContentsOfFile:)

Here is my code:

@interface SlideViewController : UIViewControllerExtended <UIScrollViewDelegate> {

    ScrollViewController *slider;
    IconView *currentChapter;
    NSMutableArray *chapters;
    NSMutableArray *views;
    UIImageView *controller;

}

The lazy load function:

- (void) loadImageToScrollView:(NSInteger)chapter withPage:(NSInteger)page {


    if (page < 0) return;
    if (page >= chapterCount) return;

    if([views objectAtIndex:page] != [NSNull null]) return;

    NSMutableArray *all = [[currentChapter getImages] copy];

    if(!([[all objectAtIndex:page] rangeOfString:@".mp4"].length > 0)) {
        controller = [views objectAtIndex:page];

        if((NSNull *)controller == [NSNull null]) {

            NSArray *paths = [[all objectAtIndex:page] componentsSeparatedByString:@"."];

            NSString *name = [[NSString alloc] initWithString:[paths objectAtIndex:0]];
            NSString *ending = [[NSString alloc] initWithString:[paths objectAtIndex:1]];

            NSString *file = [[NSString alloc] initWithFormat:@"%@", [[NSBundle mainBundle] pathForResource:name ofType:ending]];

            UIImageView *tempImage = [[UIImageView alloc] initWithFrame:CGRectMake(page * 1024, 0, 1024, 768)];
            UIImage *img = nil;
            img = [[UIImage alloc] initWithContentsOfFile:file];

            [tempImage setImage:img];
            [tempImage setTag:page];

            self.controller = tempImage;
            [tempImage release];

            [slider addSubview:controller];
            [views replaceObjectAtIndex:page withObject:controller];

            [name release];
            [ending release];
            [file release];
        }

    }

    [all release];
}

The unload view method (which does not seem to work):

- (void) unloadPage: (int) page {
    if(page < 0) return;
    if(page >= chapterCount) return;
    if((NSNull *)[views objectAtIndex:page] != [NSNull null]) {
        UIImageView *viewToDelete = [views objectAtIndex:page];

        [viewToDelete removeFromSuperview];

        [views replaceObjectAtIndex:page withObject:[NSNull null]];
    }
}
  • 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-16T18:11:48+00:00Added an answer on May 16, 2026 at 6:11 pm

    The problem is solved by watching the #104 video session at WWDC2010. Which can be found on the Apple Developer site.

    So if you have problem with memory leaks while loading big images, check it out. It’s really, really useful.

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

Sidebar

Related Questions

I have a huge problem with this method im trying to make. I have
I have this huge domain object(say parent) which contains other domain objects. It takes
i have this dictionary: a) 2012 UN NEWNW = ( 2012/06/04 Saudi Arabia Huge
I have a huge string that looks like this: Text Text Text Text Text
I had a huge file for creating this GUI and I have shortened it
I have a huge autocomplete field with a list of exams. This field prepends
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have this very huge XML file of size 2.8GB. This is Polish Wikipedia's
This is a problem I have been trying to track down for a couple
I have a huge array that has to be read by different threads in

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.