ZhouWeikuan/cocos2d — Issue #44: CCTexture2D should not use finalize() to clean up GL Textures
Author: chrisbtreats
Created: 2011-10-20 02:56:44+00:00
State: open

Finalizers are not guaranteed to be called in a timely manner if at all and should not be used to release the GL textures.

I performed a local test of unloading the texture whenever CCTextureCache.removeTexture(CCTexture2D) and the native heap memory no longer grows and I no longer receive out of memory errors.

Per http://developer.android.com/reference/java/lang/Object.html#finalize%28%29 you should be using a ReferenceQueue to receive notifications when the WeakReference is garbage collected and perform the clean up then. You will most likely need to subclass WeakReference to store the "_name" value of the texture because it won't be available once the CCTexture2D is garbage collected.