0

i am trying to remove all previously allocated ViewControllers in UIPageViewController to reduce the memory usage i have more than 100 page in UIPageViewController so it's taking too much memory and looks like the UIPageViewController does not dealloc the allocated ViewControllers

Amr Mohamed
  • 2,290
  • 4
  • 20
  • 39
  • 1
    You shouldn't have 100 controllers in memory. `UIPageViewController` works similar to a `UITableView` or `UICollectionView`, it has a data source which provides controllers, so it shouldn't keep in mem all the controllers, – danypata Jan 30 '15 at 13:12
  • i know that tableView dequeue the cells but here in pageViewController is instantiating View Controller and never release them untill the pageViewcontroller gets a memory warning or something my app has an image in each page so every image is allocated but not released , the answer here says much [question](http://stackoverflow.com/questions/10576671/uipageviewcontroller-crashes-when-flipped-too-fast-during-low-memory) – Amr Mohamed Jan 30 '15 at 13:35

1 Answers1

0

You can use the

- (void)setViewControllers:(NSArray *)viewControllers
             direction:(UIPageViewControllerNavigationDirection)direction
              animated:(BOOL)animated
            completion:(void (^)(BOOL finished))completion

method of the pageViewController to set the new array of viewControllers you want to be displayed, previous controllers will be released.

bsarr007
  • 1,914
  • 14
  • 14
  • so should i setViewControllers to only the current visible ViewController or what , can you please explain a little what is your idea ? – Amr Mohamed Jan 30 '15 at 14:13
  • Yes you can do that but you should look at `UIPageViewControllerDataSource` to avoid keep viewControllers in memory, they'll correctly be handled by the UIPageViewController. – bsarr007 Jan 30 '15 at 15:06
  • i just did that but no more pages if i swipe right or left it's not getting any new pages , what do you mean by i should look at the data source what exactly i should do there ? – Amr Mohamed Jan 30 '15 at 16:36
  • Here is an example of UIPageViewController using a data source http://www.makemegeek.com/uipageviewcontroller-example-ios/ hope this help you, you can also look at the apple documentation for more informations. – bsarr007 Jan 31 '15 at 15:49