Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I have a memory leak in the main.m, what could be leading to it?

I'm using instruments for the first time and I have a memory link in what seems to the the main.m. How can I target the problem to fix it? Im using ARC so it surprises me that there are errors in the main? What could be leading to this?

enter image description here

like image 461
DevC Avatar asked Nov 24 '13 15:11

DevC


1 Answers

The leak is in a descendant of main.

It would be wise to watch a WWDC video on using Instruments wrt leaks, you can get much more information that what you have shown.

Leaks shows where the leaked memory was allocated, the leak is because of a missing release so that can't be shown, it is missing.

One common cause when using ARC is a retain cycle. Perhaps a delegate property is strong instead or weak causing a retain cycle. Ex: Object-A instantiates Object-B. Object-B instantiated Object-C with a strong property. Object-C creates a strong property delegate pointing to Object-B. Object-A releases Object-B but Object-B can not deallocate because Object-C still has a strong pointer to it. Object-C can not deallocate because Object-B still has a strong pointer to it. At this point each is keeping the other from deallocating--a retain cycle. The answer is that Object-C should have a weak point to Object-B.

Your mission os to drill down and find the object that is being leaked and then figuring out why it is not being released. This is many times rather hard.

like image 127
zaph Avatar answered Nov 02 '22 06:11

zaph