Memory Leak in WP8/Android using Particles effect file with embeded imageData

Hi Guys,

Recently i have been investigating the memory leaks on WP8 and i figured that whenever i use particle effect, it keeps into the memory and it never releases in cocos2dx 3.0. After investigation i figured that this happens only when you use particle effect file in which image data is embedded into the json file. The reason of this is that every time image data is loaded into the memory it keeps the reference into the VolatileTextureMgr for caching purpose but when you again loads the same particle effect again, it again creates the image data and updates into the cache…

While updating it isn’t releasing the previously saved reference rather assigning the new one which ultimately leads to a memory leak… Below is the function in class CCTextureCache.cpp which i updated and which fixed the leak for me.

Earlier:::::

void VolatileTextureMgr::addImage(Texture2D *tt, Image *image)
{
    VolatileTexture *vt = findVolotileTexture(tt);
    image->retain();
    vt->_uiImage = image;
    vt->_cashedImageType = VolatileTexture::kImage;
}

Now:::::

void VolatileTextureMgr::addImage(Texture2D *tt, Image *image)
{
    VolatileTexture *vt = findVolotileTexture(tt);
    image->retain();
    CC_SAFE_RELEASE_NULL(vt->_uiImage); //This will release the old image reference before assigning the new one. 
    vt->_uiImage = image;
    vt->_cashedImageType = VolatileTexture::kImage;
}

I have tested this on WP8 but i believe this leak would present in Android as well. Please let me know what do you guys feel if this is the correct solution for my problem?

@zhangxm / @nite Maybe if you guys can quickly review this would be great and if this is the right fix then may be you guys can add it into the upcoming version of cocos2dx? Thanks.

Regards
Zeeshan