0

I am looking to present the same ViewController up to around 30 times (max). The app goes through a set sequence of information through a series of steps. The UI only contains a webview displaying textual information however sometimes a tableview is added in order for the user to answer questions based on the information. I have tried many ways however which is the most memory efficient way of accomplishing this as although i can get it working ok'ish I am getting lots of abandoned memory which is slowing the app considerably (I am using ARC)

Option 1 I have tried using UIPageViewController which works fine however on iPhone 4 it is sluggish and laggy i.e

[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];

Option 2 I have tried pushing the viewcontroller (on to itself) which again works fine however the memory is not getting released and the abandoned memory increases up to about 20mb a heapshot.

The user doesn't have to go back to the previous view so tried deleting the viewcontrollers in the stack as i was going along but memory still increasing.

I have been struggling with this issue for weeks surely there is a memory efficient solution somewhere?

A pint for the successful answer before the Mac gets thrown out the window:)

Thanks in Advance

rmaddy
  • 314,917
  • 42
  • 532
  • 579

4 Answers4

1

A ViewControlle may contain too many resource such as Image ,ImageView, View, Label ... All these UI unit will occupy a lot of memory . So I think the best way to present 30 view controllers has two point to be take notice of.

  1. Using Scroll view to display the content, all the elements in your view controller can be put in it.
  2. Using LAZY LOAD to display the content. Combining with Scroll view ,you can using a cycle scroll view. Cycle scroll view will load the recent three images and keep them in memory ,so no matter how many views will be presented ,memory will keep on a low level.
lynulzy
  • 561
  • 7
  • 19
1

Try This Reload View Controller. Code to display Multiple items.

Achal Gandhi
  • 151
  • 7
0

I'd stick with the UIPageViewController. Assuming you are using the dataSource and delegate methods correctly, there should be a max 3 ViewControllers in memory at any given time (the currently displayed VC, the next VC, and the previous VC). iOS will take care of the memory management for the ViewControllers on either side of these.

If you want a more detailed answer, you should post some code. It is not clear from your question what you're trying to accomplish.

Nick
  • 2,361
  • 16
  • 27
0

I don't know if this answer is pint worthy, but I think deleting the view controllers from the stack as you go is the appropriate way to do it (preferably after you've presented the next view controller). Since you're using ARC and the view controllers aren't being removed from memory, you must have a circular reference somewhere. I'd try to find that circular reference because, no matter the route you take, if that circular reference persists, those view controllers will never leave memory. There are a few easy things you can do to help find it:

First, check all the references to the view controllers that aren't being deleted. Are their they set to nil?

Second, check any place where a view controller is passed into a block (including where self or a property of self is referenced from a block). Is that block being retained anywhere? Or is it running to completion and being destroyed?

Third, try profiling the application. Sometimes, going into the Build menu and clicking "Profile" can turn up interesting results.

And finally, you can always give Instruments a try. I don't know how much you'll find out from there, other than that you have a memory leak, but it may be worth a shot if all else fails.

dudeman
  • 1,106
  • 8
  • 19