UIPageViewController with Images in iPad3 caches all viewcontrollers in memory

251 Views Asked by At

In ARC, I have customised UIPageviewController as MyPageViewController. I am adding MyPageViewController as a childViewController to RootViewcontroller. The Transition Type is set as Curl.

ImageViewControllers are added as viewControllers of MyPageViewController like this:

ImageViewController *startingViewController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];
ImageViewController *startingViewController2 = [self.storyboard instantiateViewControllerWithIdentifier:@"ImageViewController"];

NSArray *viewControllers = @[startingViewController1, startingViewController2];
[self.myPageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];

self.myPageViewController.delegate = self;
self.myPageViewController.dataSource = self.pageModelController;
[self addChildViewController: self.myPageViewController];
[self.view addSubview: self.myPageViewController.view];
[self.myPageViewController didMoveToParentViewController:self];

Each ImageViewController has 4 different UIImageViews on it. As these Images can be HD images, in order to avoid caching, I am setting the image using:

[UIImage imageWithContentsOfFile:]

But each time I turn a page in pageViewController, I can see 15 MB increased to the memory and it is not going down, unless I pop back this whole RootViewController.

But this happens only in iPad3, whereas memory is not increasing in iPad2. Both has iOS 7.1 installed.

To MyPageViewController, only 2 viewControllers(ImageViewController) are being added at a time using,

- (UIViewController *)pageViewController:(PMPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController;
- (UIViewController *)pageViewController:(PMPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController;

In viewDidUnload of ImageViewController, I am setting every views & objects to nil;

So I guess that, iPad3 is not releasing the view controllers that are once added to it, whereas iPad2 releases the previous viewControllers and keeps only the current ones.

Is that really the same or there is any other workarounds for this...

Can someone help me on this please.. I have been spending more than a week on this issue now.. Any kind of suggestions would be more helpful..

1

There are 1 best solutions below

0
On BEST ANSWER

Sorry guys, that was my mistake again. There is another PhotoFrame image we are setting behind the main image. That imageview gets a direct UIImage data. I should have referred the image Path instead.

I didn't notice that earlier. When I changed it to UIImage imageWithContentsOfFile:, it worked as a charm...