Will TextureMaterial.dispose() make the TextureMaterial’s bitmapdata available to GC provided that it’s not in the AssetLibrary? Or do I have to get rid of that separately?
How to properly dispose of a TextureMaterial?Software: Away3D 4.x |
||
|
||
Richard Olsson, Administrator
Posted: 16 June 2012 01:12 PM Total Posts: 1192 [ # 1 ] You have to manually dispose your texture, since you were the one who created it. If it was created by loading into the asset library, you can rely on the asset library to remove and dispose assets by using for example removeNamespaceAssets(). |
||
synkarius, Member
Posted: 16 June 2012 02:15 PM Total Posts: 64 [ # 2 ] Okay. And to manually dispose of a TextureMaterial, I just call TextureMaterial.dispose() and that takes care of everything (in terms of GC and memory cleanup)? Do I need to do this?:
TextureMaterial.BitmapTexture.BitmapData.dispose(); —- or is that overkill? I ask because in my project, I am using some “recyclable” textures that I want saved in the AssetLibrary and some “use-once” textures which I don’t. For the “use-once” ones, I need to know how to get rid of them. |
||
Richard Olsson, Administrator
Posted: 16 June 2012 02:19 PM Total Posts: 1192 [ # 3 ] You’ll need to dispose the texture and the material independently. You don’t have to dispose the BitmapData instance though, since disposing the texture will lose the last reference (inside Away3D) to it making it eligible for garbage collection.
The reason you DO need to dispose texture and material independently is that as far as Away3D knows, the texture may be used by several materials. It is therefor not safe for the engine to dispose it automatically when you dispose the material, instead requiring you (since you have a better knowledge of your app’s memory management) to do so once you see fit, i.e. once you know that there are no materials that still use the texture. |
||
|