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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:22:06+00:00 2026-06-18T14:22:06+00:00

I am using a separate .h , .m , and .xib files for each

  • 0

I am using a separate .h, .m, and .xib files for each UIViewController based page of a UIPageViewController based picture book. Each page is loaded with animations, music, etc. and takes about 4MB of memory. In Instruments, the free memory drops down about 4MB as each page is loaded. This memory is never released as the pages are turned. It eventually gives memory warnings. UIPageViewController seems to keep each page it instantiates in memory and won’t unload it. So when pages are turned fast, the app crashes.

I would like to be able to unload all pages except the 3 needed by UIPageViewController – the previous, current, and next pages. How can I unload undesired pages since they were instantiated by UIPageViewController.

Below is the Array of the pages that UIPageViewController pulls from. All of the pages (Page1, Page2, etc.) basically just load image files, provide basic animation, and have music.

    //ARRAY OF PAGES    
pageArray = [[NSArray alloc] initWithObjects:
        (id)[[Page1 alloc] initWithNibName:nil bundle:nil],
            [[Page2 alloc] initWithNibName:nil bundle:nil],    
            [[Page3 alloc] initWithNibName:nil bundle:nil],    
            [[Page4 alloc] initWithNibName:nil bundle:nil],    
            [[Page5 alloc] initWithNibName:nil bundle:nil],    
            [[Page6 alloc] initWithNibName:nil bundle:nil], 
            [[Page7 alloc] initWithNibName:nil bundle:nil],
            [[Page8 alloc] initWithNibName:nil bundle:nil],
             // continues all the way up to page 47
             [[Page47 alloc] initWithNibName:nil bundle:nil],
             nil];

I’ve left out the standard initialization for UIPageViewController. It uses “nextPageNumber” to pull the right page from the pageArray above to create a new page object.

-(void)turnPageForward{

[pageController setViewControllers:[NSArray arrayWithObject:[pageArray objectAtIndex:nextPageNumber]]
                         direction:UIPageViewControllerNavigationDirectionForward
                          animated:YES completion:^(BOOL finished){
                          }];

}

I have tried creating an object “pageIndex” (see below) that is set to nil after providing it to the pageController. It didn’t work. The page still took up memory well after the pages had advanced.

//PROGRAM PAGE FORWARD

-(void)turnPageForward{

UIViewController * pageIndex =[pageArray objectAtIndex:nextPageNumber];  //nextPageNumber is the next page to load

[pageController setViewControllers:[NSArray arrayWithObject:pageIndex]
                         direction:UIPageViewControllerNavigationDirectionForward 
                          animated:YES completion:^(BOOL finished){
                          }];                                  
pageIndex = nil;                            

}

I’ve looked through stackoverflow for posts using the same way of supplying pages to UIPageViewController, but haven’t found anything close. The closest was “ARC not releasing memory when going “back” in navigation controller” but doesn’t set the view controllers the same way.

I’ve tried to set the undesired pages to nil so ARC can remove them with no luck. Any suggestions or alternate paths I should try? I like the page curl effect and have not been able to find a good one elsewhere that does horizontal page curls.

Thanks! Eric

  • 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-18T14:22:07+00:00Added an answer on June 18, 2026 at 2:22 pm

    “UIPageViewController seems to keep each page it instantiates in memory”

    No, you’re doing that by instantiating all those “pages” (controllers), and putting them into an array (the memory jumps as you turn the page because the controller’s view is not actually loaded until you display it, even though the controller has been instantiated. But once you’ve done that, your controller retains its view and the array retains the controller). You just need to keep some kind of count of which page you’re on, and in the implementation of viewControllerBeforeViewController: and viewControllerAfterViewController:, instantiate a page there. When you go away from that page, its controller will be dealloc’d. If the loading is slow, you might need to keep an array that has the current page and the ones before and after — UIPageViewController does do that if you have it set to scroll instead of page curl for the transition.

    I made a simple test app like this:

    @implementation ViewController {
        int count;
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        count = 1;
        self.pager = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationDirectionForward options:nil];
        self.pager.dataSource = self;
        self.pager.delegate = self;
        Page1 *first = [[Page1 alloc] initWithNibName:@"Page1" bundle:nil];
        [self.pager setViewControllers:@[first] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
        [self addChildViewController:self.pager];
        [self.view addSubview:self.pager.view];
        [self.pager didMoveToParentViewController:self];
    }
    
    
    -(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
        if (count > 1) {
            NSString *nibName = [@"Page" stringByAppendingFormat:@"%d",count-1];
            UIViewController *prev = [[NSClassFromString(nibName) alloc] initWithNibName:nibName bundle:nil];
            count -= 1;
            return prev;
        }
        return nil;
    }
    
    -(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
        if (count < 3) {
            NSString *nibName = [@"Page" stringByAppendingFormat:@"%d",count+1];
            UIViewController *next = [[NSClassFromString(nibName) alloc] initWithNibName:nibName bundle:nil];
            count += 1;
            return next;
        }
        return nil;
    }
    

    My example only has 3 pages, but it illustrates one way to do this. I put logs in the dealloc methods of the 3 controllers, and they were called when I navigated away from them.

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

Sidebar

Related Questions

Using C#, I want to generate 1,000,000 files from DB, each record in separate
Anyone install both? Using each for separate projects obviously. Shouldn't be a problem, I'm
I'm using Admob SDK and Tobonet SDK . Using each of them in separate
Currently I am using separate configuration files and calling them like: protected override void
I am using separate hbm.xml files for hibernate mappings and facing problem in defining
I have recently switched from using separate resource files to using a texture atlas.
I want to create UI elements programmatically without using xib files. All of the
I have two versions of a product and am using separate Hg repositories for
I have bind 2 separate tables using BindingSource. Left grid contains student table and
I have a subclassed NSTextView that I am manipulating in a separate thread (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.