Colors in tools for finding memory leaks

I am currently looking for a memory leak in my iPhone application. I use Tools to track code that causes a leak (becoming more and more a friend of Tools!). Now the tools show two lines: one dark blue (line 146) and one lighter than blue (150). From some trial and error, I learned that they are somehow related, but not good enough in Objective-C and memory management to really understand how.

Does anyone know why different colors are used and what could be my problem?

I tried to free numberForArray, but the application crashes when the last line is displayed in the selection view.

All ideas are welcome!

alt text

(By posting this, I also understand that line 139 is redundant! By itself, this is already an improvement ;-)

+4
source share
2 answers

Ok, let's take a look at the behavior of the object / owner of this code ...

numberForArray assigned the result -NSString stringWithFormat: which is an automatically issued object. This means that you do not want to free him (as you discovered).

This object is then added to the glucoseLoader NSMutableArray, which will be retain . You loop 100 times, creating 100 objects and adding them to glucoseLoader . When the glucoseLoader freed, on line 154 it will also free all objects added to it.

But wait, there's more: firstComponentRange is created from glucoseLoader using -NSArray initWithArray: When you do this, all elements of the source array will be added to the destination, which will save them again.

So when / how do you release firstComponentRange ?

+3
source

The tools tell you that firstComponentRange is not freed (slight leak). Since the array retains its contents, you have thus eaten 100 leaks of NSString leaking out on lines with a darker strip (a more significant leak).

0
source

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


All Articles