Decrease UIImages memory from the camera with tools

My application using ARC does the following:

  • Uploads a picture taken by the camera.
  • Compresses an image for use as a thumbnail.
  • I do this using [UIImage imageWithData: UIImageJPEGRepresentation (original, 0.1f)]
  • I set an uncompressed image link to nil for ARC to free up memory

Repeating this sequence will mean that several compressed thumbnails are displayed on the screen. After about 7 or 8 snapshots, the application crashes due to low memory.

In Tools, I try to use Allocations in tandem with Memory Monitor to find the source of my problem.

Statistics of some tools:

Highlight - Live Bytes jumps about 2 MB after shooting, but then decreases by 1.5 MB after the original image link is set to zero. It seems good, but ...

Here is the possible state of the application. #Living seems very high relative to Live Bytes, right?

Live Bytes #Living #Transitory Overall #Overall Bytes 3.72 MB 24538 80679 90.1 MB 105301 

Memory monitor (tracking monitoring head). My application starts with 7.5 MB, and with one shot, an increase of ~ 13 MB is obtained. For the state that I listed above, Memory Monitor says that the application occupies 72.67 MB of β€œReal memory” and 123.79 MB of virtual memory.

Given that Live Bytes are very small, I know that I am doing something right. However, given that the amount of memory in other places is large, I am also sure that I am doing something very wrong. Any ideas what this might be, or how to track it?

+6
source share
2 answers

Eitan27,

This is not an ARC problem. It's about how to manage several large items in memory. There are several mechanisms in iOS that will help you here. If you are writing an image for the flash, and then reopening it as memory mapped data, you will basically solve your problem. How? The OS controls the mapping to your resident memory space with immutable data. Since these elements are immutable and therefore never contaminated, it can then flush the displayed pages when necessary. The disadvantage of this mechanism is the limited number of file descriptors available for each application.

Andrew

+2
source

Use the @autoreleasepool block:

 @autoreleasepool { //code that inits the UIImage and sets it to nil } 

See ARC Provides a New Expression for Partition Management Autorelease Pools Navigate to ARC Release Notes

0
source

Source: https://habr.com/ru/post/905784/


All Articles