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

Not able to clear the data

(1/2) > >>

JKumar:
HI,

         I am trying to load the followings

1. A serialized md2 model.
2. A texture
3. A primittives.

It runs fine for the first time but when i restart the app, it gives me OutOfMemory exception.

i used

mCharacter.clearObject();


but the same issue is coming.


Can anyone help out in getting  a way as How to release the resources onDestroy?

EgonOlsen:
clearObject() isn't meant to be used for this. Actually, it's not meant to be used at all except for some very special cases. IF you want to reload the model, you have to remove it from the world, null all references to it in your own code and then load it again. But you don't have to, if this is about Activity handling. Just re-use the orginal instance in the new Activity.

JKumar:
Hi,


   There are 2 cases i encountered using your NinjaDemoActivity class

1.When declaring varibales as attribute of the activity.

    I added following code taking in the try block in onCreate method of your NinjaDemoActivity class

 mCharacter  =    null;
mArena     =   null;
mAnimation   =    null;
         
mCharacter   =  Loader.loadSerializedObject(getResources().openRawResource(R.raw.model_new5));
mArena        = Primitives.getPlane(4, 15);
mAnimation   = mCharacter.getAnimationSequence();
      
I have not added any of the object to the world. Its just the above lines only.
This run correctly for first time but thrwos OutOfMemeory when i restarts the app.

And

2.When declaring varibales as local(inside a block or method).

 Object3D mCharacter     =    null;
 Object3D mArena     =   null;
 Animation mAnimation    =    null;
         
mCharacter   =  Loader.loadSerializedObject(getResources().openRawResource(R.raw.model_new5));
mArena        = Primitives.getPlane(4, 15);
mAnimation   = mCharacter.getAnimationSequence();

In this case everything runs fine at evertime i restart the app.



As i need the attributes for the activity to be used a other places also. I feel the data is not getting cleared in the engine.

EgonOlsen:
And you are not adding them to a world in some other place? What's the point in loading them then? Seems to me like somebody is still keeping a reference to the instance. Either you in your own code or jPCT, because you are adding them to a world. Loading alone doesn't need anymore memory than the instance itself needs. Once nulled, it can be collected by the garbage collector. Another option might be, that the gc just sucks on Android. Try to call the compact() of the MemoryHelper in jPCT-AE's util package to see, if this frees some memory. If not, check for references in your code.

Ulrick:
Hi,

I actually have a similar problem.

In my case, I load everything and it work perfectly at every run, but now I would like to change loaded object while the application run, but I have problems when I try to free memory.

In my case I don't want to clear the world object, but just "unload" some 3d objects and textures and load some new objects.

As far as I unload Textures, it works fine with the memoryhelper in cleaning memory, but it seems that 3d objects are not cleaned (actually the test I did was to load a 3d object, than unload it and load a new one, but I get out of memory exception (in the test, it is not the only object I have in the world, actually used memory is already at the limit when loaded the first 3d object and I need to unload it to loa a new one, because just loading the new one give the out of memory exception).

I tried already to invert the loading in order to be sure that was not a problem with the second object, and it works.

To make things clearer, my case is that for example I have 10 objects loaded with memory usage at the limit. One object more fire the out of memory, so I need to unload one object in order to load a new one.

How can I unload an object? Am I doing something wrong?

Thanks,

Massimo

Navigation

[0] Message Index

[#] Next page

Go to full version