Memory deallocation in CCTMXTiledMap

Memory deallocation in CCTMXTiledMap
0.0 0


i’m using several tiled maps in my game.when i test the code below,i found about 1.5M memory increasement
each circulation.My tilemap’s size is 50*50 with 160*80 tile size.
for (int i = 0; i < 30; i++)
m_Map = CCTMXTiledMap::tiledMapWithTMXFile(str_map);
i wonder the map is not clean completely and my game is based on tilemap,is there anybody can help me?
Thank you!


Which platform are you using?

CCTMXTiledMap is inherit from CCObject, so when you invoke CCTMXFiledMap::tiledMapWithTMXFile static method, it use CCAutoreleasePool to cache this object in memory, and is marked as “autorelease”.
The memory will be released at the next message loop.
For more detail, please read this thread Memory deallocation in Cocos2d-x

You may try

for (int i = 0; i < 30; i++) {
    CCTMXTiledMap* pMap = new CCTMXTiledMap;

If it still have any problem, please tell me your platform :slight_smile:


Thanks for the quick reply.
my main platform is win32,i also tested it in iphone with Xcode.
the results are same.

the test code
for (int i = 0; i < 30; i++) {
CCTMXTiledMap* pMap = new CCTMXTiledMap;
also causes the memory increasement each circulation.


Which approach are you using to watch the memory increasing?
We would reproduce it.


My approach to watch memory
Windows: Task Manager
MAC: Instrument


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


@Songyuan Zhao,
I have take a test on both win32 & ios platforms. My test code like this:

bool HelloWorld::init()

    schedule(schedule_selector(HelloWorld::test), 1);


static int s_nCount = 0;

void HelloWorld::test(ccTime dt)
    for (int i = 0; i < 30; i++) {
        CCTMXTiledMap* pMap = new CCTMXTiledMap;

    s_nCount += 1;

    if (10 == s_nCount)

The file “iso-test.tmx” and “iso-test.png” is from folder “tests/Res/TileMaps”.

On ios, I took a screenshot about the memory allocation.

You can see there are 10 times of memory allocation, but they are all deallocated.

On win32, the memory is really increased each circulation. The memory increased about 200M when the circulation run 10 times.
But I think it’s a bug of the PowerVR library have be known. The texture can’t be released in opengl.
In the test code, the file “iso-test.png” size is 512 * 256, and it’s loaded 300 times without released. So I think it’s the reason of the 200M memory increased.

By the way, the bug of the PowerVR library have be proved by developer. See the following image:


it seems wouldn’t be a problem on ios.
thanks a lot.