I am developing a game using Cocos2D for iOS.
There are some scenes like menu and the like and a main game scene. On the main scene there is only three dynamic objects. These objects periodically shoot at each other (until these objects are killed or moved out of the scene).
Now the problem: the game constantly eats up memory. And I want to find out what I am doing wrong.
There are no obvious leaks like over-retained objects. Scene gets dealloc
ed, objects gets removed from parents and cleaned up, animations gets stopped etc.
Anyway, the memory keeps going somewhere. I am using following code
+ (void) reportMemory
{
struct task_basic_info info;
mach_msg_type_number_t size = sizeof(info);
kern_return_t kerr = task_info(mach_task_self(),
TASK_BASIC_INFO,
(task_info_t)&info,
&size);
if (kerr == KERN_SUCCESS)
NSLog(@"Memory in use (in Kbytes): %f", info.resident_size / 1024.0);
else
NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
}
to find how much memory consumed at each start of the scene. And reported number is always greater then previous one.
I tried to use allocations profiler but honestly I wasn't able to figure out anything useful. I see that total living bytes are basically the same, but process constantly allocates and deallocates something.
What would you suggest me to look at? Basically, I am seeking advices for how to debug memory operations in my case.
EDIT (What have helped me):
It turned out that I had NSZombieEnabled turned on. Basically, it was the main factor for constant memory consumption increases. Some useful information and a tip can be found in a @coneybeare answer
The second most useful thing was to use Instruments (Leaks and Allocations) as @Jack suggested. It helped me to find couple of subtle leaks.