jPCT-AE - a 3d engine for Android > Support

how to clear entir cache from md2 model loading??

(1/2) > >>

Davi:
I have two activities.one is first page,it has a start button,when I clike this button,it will load my two md2 models at the same time ,when they load completely,it will skip two my game activity,in my game activity , this time,two models work normally, when I click key Back,it will go back to my first page,but at this time,if I click the start button again,my app will crashed,and there will be some error messages in logcat:

--- Code: ---
11-14 17:14:08.106: E/AndroidRuntime(19642): java.lang.OutOfMemoryError
11-14 17:14:08.106: E/AndroidRuntime(19642): at com.threed.jpct.Mesh.<init>(Mesh.java:143)
11-14 17:14:08.106: E/AndroidRuntime(19642): at com.threed.jpct.Mesh.cloneMesh(Mesh.java:332)
11-14 17:14:08.106: E/AndroidRuntime(19642): at com.threed.jpct.Loader.loadMD2(Loader.java:1328)
11-14 17:14:08.106: E/AndroidRuntime(19642): at com.threed.jpct.Loader.loadMD2(Loader.java:131)
11-14 17:14:08.106: E/AndroidRuntime(19642): at org.mxr.app.ModelLoading.loading(ModelLoading.java:75)
11-14 17:14:08.106: E/AndroidRuntime(19642): at org.mxr.app.ModelLoading.run(ModelLoading.java:65)
11-14 17:14:08.106: E/AndroidRuntime(19642): at java.lang.Thread.run(Thread.java:1102)
11-14 17:14:08.576: E/ActivityManager(1327): fail to set top app changed!


--- End code ---
this is out of memorry,I just want to know how to clear entire cache after load md2 models before go back to first page?


EgonOlsen:
Which cache? There is no cache or something. Personally, i would try to avoid reloading stuff at all. If you have to, make sure that all references to your models are cleared. Keep in mind that (as said before in another thread)


--- Code: ---
model=Loader.loadXXX(...);


--- End code ---

isn't the same as


--- Code: ---model=null;
model=Loader.loadXXX(...);

--- End code ---

Davi:
you 2 lines code mean the global variable Object3D model is not the same as local variable Object3D model.
I have done that in onDestory(),the code as following:

--- Code: ---                @Override
protected void onDestroy() {
                model=null;
                fb=null;
                world=null;
                TextureManager.getInstance().removeTexture(texturesName);
                 Loader.clearCache();               
               }

--- End code ---
above is right?

EgonOlsen:

--- Quote from: Davi on November 15, 2011, 11:51:44 am ---you 2 lines code mean the global variable Object3D model is not the same as local variable Object3D model.
--- End quote ---
No, it has nothing to do with global against local. What it means is, that if model (for example) consumes 4mb, the first code will consume 8mb (old reference plus new reference) during load while the second one only uses 4mb. This isn't always clear, which is why i mention it from time to time when it comes to garbage collection related questions.

--- Quote from: Davi on November 15, 2011, 11:51:44 am ---I have done that in onDestory(),the code as following:

--- Code: ---                @Override
protected void onDestroy() {
                model=null;
                fb=null;
                world=null;
                TextureManager.getInstance().removeTexture(texturesName);
                 Loader.clearCache();               
               }

--- End code ---
above is right?

--- End quote ---
It's ok, but it would be better to do:


--- Code: ---                @Override
protected void onDestroy() {
                TextureManager.getInstance().removeTexture(texturesName);
                model=null;
                fb.freeMemory();
                fb.dispose();
                fb=null;
                world.dispose();
                world=null;
                 Loader.clearCache();               
               }

--- End code ---

Also make sure that this method will actually be called in your case. It's more likely that your Activity will get paused/stopped instead of being destroyed.

Davi:
   
--- Quote ---   @Override
    protected void onDestroy() {
                TextureManager.getInstance().removeTexture(texturesName);
                model=null;
                fb.freeMemory();
                fb.dispose();
                fb=null;
                world.dispose();
                world=null;   
                  Loader.clearCache();               
               }

--- End quote ---

thank you very much, it seems can't release all texture memory from my system,can you tell me how to clear all memory completely,
use as following code:

--- Code: --- TextureManager.getInstance().removeTexture(texturesName);
 TextureManager.getInstance().flush();
TextureManager.getInstance().removeAndUnload(textureName,frameBuffer)

--- End code ---
right?

Navigation

[0] Message Index

[#] Next page

Go to full version