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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:32:25+00:00 2026-05-29T18:32:25+00:00

I have a problem with memory management. A have a scrollview and every page

  • 0

I have a problem with memory management. A have a scrollview and every page in it loads from array of view controllers.
I load scrolview page calling the folowing method:

- (void)loadScrollViewWithPage:(int)page {

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


    BancaTableViewController *controller = [viewControllers objectAtIndex:page];


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

        controller=[[BancaTableViewController alloc] initWithPageNumber:page];
        controller.banks=banks;
        [controllersetDelegate:self];
        [viewControllers replaceObjectAtIndex:page withObject:controller];
        [controller release];
    }

    // add the controller's view to the scroll view
    if (nil == controller.view.superview) {
        CGRect frame = scrollView.frame;
        frame.origin.x = frame.size.width * page;
        frame.origin.y = 0;
        controller.view.frame = frame;
        [scrollView addSubview:controller.view];
    }


}

This is my unload view controller method which unloads all controllers except the controller of curent page but it doesn’t seem to work because the memory keep increasing.

- (void)unloadScrollViewWithPage:(int)page {
    for (unsigned i = 0; i < kNumberOfPages; i++) {
      if(i!=page){
       [viewControllers replaceObjectAtIndex:i withObject:[NSNull null]];
      }
    }
}

How to write the unloadviewcontroller correctly?

  • 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-29T18:32:27+00:00Added an answer on May 29, 2026 at 6:32 pm

    You’re adding a hard pointer to scrollView, but you never remove the object. (i.e. you keep adding subViews to scrollView and never remove them.

    [scrollView addSubview:controller.view];
    

    Try this…

    Add a tag to your controller view when you add them to the scrollView, then remove it before you load a new controller. Check syntax – from memory – not tested

    if ((NSNull *)controller == [NSNull null]) {
    
        controller=[[BancaTableViewController alloc] initWithPageNumber:page];
        controller.banks=banks;
        controller.tag = 3;
        [controllersetDelegate:self];
        [viewControllers replaceObjectAtIndex:page withObject:controller];
        [controller release];
    }
    
    // add the controller's view to the scroll view
    if (nil == controller.view.superview) {
        CGRect frame = scrollView.frame;
        frame.origin.x = frame.size.width * page;
        frame.origin.y = 0;
        controller.view.frame = frame;
        [scrollView removeFromView:[scrollView viewWithTag:3]];
        [scrollView addSubview:controller.view];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here's a problem with memory management issue. Say i have a view A, it
I have a problem with out of memory when I'm trying load a few
I have a problem regarding the memory management when adding objects to a NSMutableArray
I have a little problem with memory management in a Windows Service written in
first, i followed this tutorial: three20 github tutorial i have a memory management problem
I have a problem regards the memory management of my game on Android 2.2.
I have a memory management problem I can't get my head around on iOS.
I have this huge problem with memory management. The problem : I've got a
I have problem with the way I treat the memory management in iphone..please please
I have a problem with a memory leak in a .NET CF application. Using

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.