In Part 1 I've investigated why the Leaks instrument doesn't catch a leak. This video was a direct result of one of the discussions over at the fantastic Facebook iOS Developers Group (http://gcx.cx/fbios).
...To prevent the leak you could implement a method that is called before you nil your array that loops through eacht object in the array and releases it (thus decreasing retain count to 1). Then when you nil your array the retain count is decreased again (becoming 0 and deallocing the object).
So, instruments wouldn't know if youre going to release the objects before niling its references and cant display the "leak" before that is done. Because only after that, the leak occurs.
Sorry, I know this posting is older but I just found it and wanted to comment on it:
As I understand a leaking object occurs when an object that is retained in memory loses all its references. So until you nil your array, the references arent lost and no leaking occurs. Also, in your for-loop I think you mention the retain count being 1. I think the retain count is 2 (alloc adds +1 and addObject to your array adds +1).
...To prevent the leak you could implement a method that is called before you nil your array that loops through eacht object in the array and releases it (thus decreasing retain count to 1). Then when you nil your array the retain count is decreased again (becoming 0 and deallocing the object).
So, instruments wouldn't know if youre going to release the objects before niling its references and cant display the "leak" before that is done. Because only after that, the leak occurs.
MrMDomi 4 months ago
Sorry, I know this posting is older but I just found it and wanted to comment on it:
As I understand a leaking object occurs when an object that is retained in memory loses all its references. So until you nil your array, the references arent lost and no leaking occurs. Also, in your for-loop I think you mention the retain count being 1. I think the retain count is 2 (alloc adds +1 and addObject to your array adds +1).
MrMDomi 4 months ago
Awesome!
Now I finally understand why leaking 'doesn't work' :)
Great tuto!
XRaYNL 5 months ago