CFString memory usage (immutable) continues to grow in iOS app

I check the memory usage of my iOS application with tools and find that CFString continues to stand out and grow. I used the StringWithFormat method, and not something like [[NSString alloc] init] when creating an NSString object in my code. How can i stop this? The following image is a screen capture of the instrument's output signal.

Please tell me if the necessary information for the question is missing.

Instrument's screenshot

+4
source share
2 answers

It’s good practice to use custom autoresist pool blocks if you create many temporary objects using convenience constructors. Because objects created using convenience constructors are auto-implemented, they cannot be immediately released. This is the reason for using a burst in memory.

From Apple :

Many programs create temporary objects that are auto-implemented. These objects add to the end of the program memory block. In many situations, allowing temporary objects to accumulate until the end of the current iteration of the event loop does not lead to excessive overhead; however, in some situations, you can create a large number of temporary objects that are substantially added to memory and you want to get rid of faster. In these, in the latter case, you can create your own autoresist pool block. At the end of the block, temporary objects are freed, which usually leads to their release, thereby reducing program memory footprint.

http://www.cocoanetics.com/2009/08/understanding-autoreleasing/

0
source

In our case, I found a continuous leak of NSStrings (many of which belong to the NSPlaceholderString class, which is part of the class cluster) due to the fact that NSZombieEnabled is included in the scheme.

Disabling this source resolves this source of memory leak.

0
source

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


All Articles