Reputation: 318
I have already handled the function -(void) handleMemoryWarning:(NSNotification*)
notification in my AppDelegate and it is doing a pretty good job.
I have taken a good deal of time to handle every memory leak in my program.
But some how I still see some memory leak and eventually a memory crash after I receive a memory warning level 2 or sometimes 3.
Is there a way that I can collect some data and send it to my server just before my app is going to crash BECAUSE OF MEMORY?
I am using Crittercism to handle other exceptions.
Please don't give ways to reduce memory in the existing code.
Upvotes: 0
Views: 325
Reputation: 1398
user this to clear memory
[[CCDirector sharedDirector] purgeCachedData];
[[CCTextureCache sharedTextureCache] removeAllTextures];
[CCTextureCache purgeSharedTextureCache];
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];
[CCSpriteFrameCache purgeSharedSpriteFrameCache];
and in
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
//you just save your data.
}
Upvotes: 1
Reputation: 10860
To check loaded textures you can call
[[CCTextureCache sharedTextureCache] dumpCachedTextureInfo];
it will print to console all loaded textures and their size in memory. To avoid memory crashes on all devices your app should not use more than 100 Mb of memory(i mean retina devices). Even such amount will cause memory warnings, but no crashes.
To check, where your app begins to load resources, you can use Activity Monitor from instruments. It allows to see how much memory does your app use. Attached instrument will cause increase of used memory, but if your app will crash with Activity Monitor attached and will not crash without it, it means that your memory usage is critical and has to be reduced.
Upvotes: 0