Ok, so I've been thinking for some time about a small lightweight class that would help me keep track of what's been dealloced and what has been not. Additionally, the class keeps track of how many objects of a specific class have been used in the app, as well as a maximum amount of them used in any given moment
The principle is very simple - whenever our own object is initialized, we add a macro MEMORY_MONITOR_CLASS_ALLOC; in it's init method. Similarly, MEMORY_MONITOR_CLASS_DEALLOC; is placed in dealloc method
To make it even easier, those methods can be placed in init/dealloc methods of the CCNode class and everything will work absolutely fine. If you have any other classes NOT of Cocos2d origins - just add those macros as I explained above
To print the results, after the app is terminated - [MEMORY_MONITOR printMe]; needs to be added in applicationWillTerminate function
And that's basically it ;)
Here is an example of the output - not that I am (on purpose) NOT cleaning my code too well:
Class CCBitmapFontAtlas - 18 instances not dealloced, total : 90, maximum : 66
Class CCLabel - 41 instances not dealloced, total : 41, maximum : 41
Class CCLabelAtlas - 0 instances not dealloced, total : 1, maximum : 1
Class CCMenu - 8 instances not dealloced, total : 8, maximum : 8
Class CCMenuItemFont - 31 instances not dealloced, total : 31, maximum : 31
Class CCSprite - 201 instances not dealloced, total : 561, maximum : 457
Class CCSpriteSheet - 8 instances not dealloced, total : 8, maximum : 8
And now when I clean things properly:
Class CCBitmapFontAtlas - 0 instances not dealloced, total : 90, maximum : 66
Class CCLabel - 0 instances not dealloced, total : 41, maximum : 41
Class CCLabelAtlas - 0 instances not dealloced, total : 1, maximum : 1
Class CCMenu - 0 instances not dealloced, total : 8, maximum : 8
Class CCMenuItemFont - 0 instances not dealloced, total : 31, maximum : 31
Class CCSprite - 0 instances not dealloced, total : 561, maximum : 457
Class CCSpriteSheet - 0 instances not dealloced, total : 8, maximum : 8
Code follows in next post