iOS Dev
iOS Dev

Reputation: 4248

UIScrollView memory warning

I have 5 custom views which inherit from CPTGraphHostingView, i.e they are 5 different plots build using Core Plot Framework. I initialize these plots and add as subviews to an UIScrollView. Each view is fullscreen, and I'm using pagination to scroll to different plot. The problem is that when I'm loading all this stuff, memory increases significantly, and there is a risk of app crash. How can I optimize the memory usage?

Upvotes: 0

Views: 289

Answers (1)

Prashant
Prashant

Reputation: 101

In this case you are loading all the CPTGraphHostingView at once because of that memory is getting increased significantly. As per description you are using horizontal pagination to load next view. You can use following option to optimise memory usage

  1. As you are putting CPTGraphHostingView on scroll view user is able to view only one graph at time. so you need to add only the view which user is currently using. When user goes to next page remove previous view from superview and make it nil. And create new CPTGraphHostingView with required data and add it to subview. This approach will keep only current view in memory.
  2. You use horizontal UICollectionView which will only keep views in memory as long as they are visible.

Upvotes: 2

Related Questions