Constantly increasing persistent memory - Removing subclauses from a view - iOS (ARC)

I have an iPad app that crashes on the iPad (first model) as it runs out of memory.

In the application, I have a main view that adds about 20 UIScrollViews (user class) in the form of subviews, each of which contains UIImageView and UIImage . When the user moves to the next page, I will remove all these routines from the supervisor, and then add 20 new UIScrollViews to the same view.

If I profile the application for allocations and memory leaks, everything is fine - the allocated memory remains about 2 MB, and the user scrolls left and right.

However, if I look at the actual memory usage in the activity monitor, I see that every time a user navigates to a new page, the real memory increases by about 20 MB. In the end, after several new pages, the application size reaches 150+ MB and crashes.

Can anyone suggest what might cause this type of behavior and how can I eliminate it?

A bit more information about the structure of the application:

  • In boot mode, images were uploaded to NSMutableArray using initWithContentsOfFile .
+4
source share
1 answer

You should not support these images in an array. Images consume a disproportionate amount of your limited memory. There are several approaches:

  • If you want to keep it simple, just do not store images anywhere. Download the image property of UIImageView by loading the image through initWithContentsOfFile and name it day.

  • If you need some RAM caching for performance reasons, you can use imageNamed instead of initWithContentsOfFile . When the application receives a warning about memory, the cache will be automatically cleared.

  • I would tend to use initWithContentsOfFile , but then manually cached my own NSCache (which is similar to a NSDictionary , except that you can set countLimit number of images onto which it should be inserted).

By the way, you do not describe what technically happens when "the user goes to the next page." If you just upgrade existing controls on an existing view controller, everything is probably fine (once you fix the NSMutableArray problem that I discussed above). If you click / present on another view controller or scroll the controls off the screen, but neglect to remove old ones from your supervisor, this will also cause problems. You can clarify what you are doing there.

On the bottom line, you just need to make sure that when you go from one page to another, you do not support links to old images or controls.

+1
source

All Articles