Memory Leaking

Memory Leaking
0.0 0


Hi all,

I have been doing some great stuff with the airplay version of cocos2d-x so thanks to everyone who made it happen.

Unfortunately during my development I have noticed that memory seems to be leaking all over the place. I thought it was my app but having loaded up the cocos2d test bed it seems the same happens in that.

I’m developing on PC and am monitoring the memory usage using the Airplay Simulator - Metrics - Memory tracking. I was going mad trying to work out what I hadn’t freed in my own code but as the tests are leaking it looks more like a cocos2d framework issue?

If you load up the testbed and just leave the app running on the menu - Heap 0 slowly continues to decrement.

If you then go into one of the test and back out, the memory never goes back up, like nothing is being freed. I.e. keep clicking ‘Actions Test’ - ‘Main Menu’ - ‘Actions Test’. If you do this with some of the worst ones (parallax, tilemap) it will run of memory really quickly and crash.

Has anybody noticed this before or have any idea of what is causing it?

Has anybody released anything using this port yet? I really like developing on PC and would love to carry on doing so but obviously having memory issues like this isn’t going to make that possible.




… also the Heap 0 allocated goes up and down like I would expect but nothing goes back on the free.


Yes - really - a memory leak exist, primarily due to engine Cocos2d-x because if you run the tests on “native” IOS project will see an increase in memory - even if nothing is done from the main menu - after some time increases the amount of used memory . This is a serious problem - I think that developers of engine should pay attention to it.


OK, we will deal with it.
We cleared the memory leaks at 0.7.2 version. Since more features added later, leaks may appear again.


Bug #483 created for this post.
Thanks for your report!


I just traced all test cases one by one, on ios 4.3 simulator & my itouch3gs with 4.2 system.
No any memory leaks appears in Instruments.
My source is the edge version on github.


We also ran cocos2dx on top of Airplay(Marmalade). When running the cocos2d test examples on our Android device(Nexus One) and iPhone 4, we saw that there are leaks as well. We took a screenshot and added it below:

This happens after we run a few of the examples in the cocos2dx test. It seems like the autorelease functionality isn’t working properly.

As for testing on Instruments, I think that Instruments won’t be able to catch the leaks because Airplay grabs a certain amount of memory in the beginning and does all memory management through it’s own memory pool. This may cause Instruments to think that there are no leaks from it’s heap when there actually are leaks in the memory pool.

NOTE: We haven’t actually been able to run the cocos2dx tests on Instruments because we are getting some strange errors in Instruments.


How can I popup this error box? I’m not familiar with airplay, especially it changes to Marmalade.


I’m not sure it is a memory leak, I had a simliar problem with the iPhone but just increased the help memory in the .icf settings file in Airplay, after doing this all the tests worked. This was a month or two ago so I’ll load up the tests again and try with Airplay (Marmalade).


Thanks, please use the lastest version 0.8.5. Anyway to certainly reproduce this leak will be appreciated!


You can reproduce it by loading 2-3 1024x1024 sprite sheets. That’s the problem I’m having. I increase the memSize but at one point it just won’t load anymore sheets and this will keep appearing.


I’ve already tried to raise the memory allocated in the icf file.
However, this error still occurs.
The problem lies more in the fact that the memory is not properly being deallocated.


Andrew any ideas what to do if I want to load multiple sprite sheets ?


Hey guys I found this link. Try checking it out


Hey can anyone tell me how the rendering is taking place in cocos2dx.
Im in contact with the marmalade support trying to figure out why I cant load my sprite sheets.


Marmalade guys have written at a number of places to call IwGxFlush()/IwGxSwapBuffers() at the end of your frame.


I ran the code using allocations.
libSystem.b.dyLib is responsible for taking up 49Mb.
This is happening somewhere in the very start.
Any clues on what this is?


Well, we need an airplay expert here.
I just write an email about this case to Max, the maintainer or cocos2d-x airplay port


I read your post on the marmalade forum. Can you locate which cocos2d function takes the 49MB memory?


Allocations doesn’t show that.
I think the 49mb is the initial memory im assigning to the app. Because the responsible caller shows thread_start