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

Optimizing memory usage by duplicated or unused Object3D

(1/4) > >>

iagofg:
Hello,

I'm wish to know which is the best way to dispose the unused Object3D that is no more necesary on the scene.

Also, I wish to know how should I proceed to minimize the memory usage when I have several instances of one Object3D in the scene, with different animation positions, translations and rotations.

Thank you!!

K24A3:
To remove an Object3D I believe you need to remove it from the world then null all references to the Object3D so the garbage collector frees it.

world.removeObject(myObject);
myObject = null;

Cloning objects wont work with objects that have different animations (every object will have the same animation timings because they use the same mesh), but you can remove triangle information from the animations by calling Animation.strip().

EgonOlsen:
It's correct that animated objects can't share meshes, but they can share the same animation instance though.

iagofg:
So making:

world.removeObject(myRef);
myRef = null; // for all the references

Sure is enought to dispose everything, including all the underlaying compiled data? I suspected that there is something else to do to free all the resources. I've asked the question the first time because my app didn't not low the memory usage doing so... sure it can be the complexity of my app that hides some lost non-nulled references, but I looked for them everywhere and I didn't found more. Maybe I make some benchmarks with IRenderHook to confirm or discard :)

On the other topic (sharing data between duplicated objects)... relating cloning meshes sure that this: Object3D myRef2 = new Object3D(myRef, true); do not work to share the same mesh?

For animated object I suppose that is necesary 1 mesh per object so you can get different animated statuses per each Object3D? is it? do you refer this when you say animated objects can't share meshes? so if animated objects share meshes all of them will get the same animation status when rendering? maybe know this is usessful if i want more than 1 object animated identically at the same time?

Finally: I'm reading the doc searching for other posibility... maybe sound a little mad, but can I add more than one time the same Object3D to the world?? I'm thinking in optimizing with IRenderHook; it can solve my problem in some scene :)

EgonOlsen:

--- Quote ---Sure is enought to dispose everything, including all the underlaying compiled data? I suspected that there is something else to do to free all the resources. I've asked the question the first time because my app didn't not low the memory usage doing so... sure it can be the complexity of my app that hides some lost non-nulled references, but I looked for them everywhere and I didn't found more.

--- End quote ---
It should be sufficient. GPU will be freed once the compiled data gets garbage collected. If you are using VBOs, you'll get a log message in that case. This won't happen of course, if you are still keeping some reference to that Object3D somewhere.


--- Quote ---On the other topic (sharing data between duplicated objects)... relating cloning meshes sure that this: Object3D myRef2 = new Object3D(myRef, true); do not work to share the same mesh?

--- End quote ---
Yes, that will make the new object use the same mesh...but i don't understand the actual question...?


--- Quote ---For animated object I suppose that is necesary 1 mesh per object so you can get different animated statuses per each Object3D? is it? do you refer this when you say animated objects can't share meshes? so if animated objects share meshes all of them will get the same animation status when rendering? maybe know this is usessful if i want more than 1 object animated identically at the same time?

--- End quote ---
If they share the mesh, they share the animation...so calling animate() on one of them is sufficient. However, you have to make sure that this object will actually be rendered or otherwise, the mesh update doesn't happen on the other objects until you call touch() on one of them. 



--- Quote ---Finally: I'm reading the doc searching for other posibility... maybe sound a little mad, but can I add more than one time the same Object3D to the world?? I'm thinking in optimizing with IRenderHook; it can solve my problem in some scene

--- End quote ---
No. One Object3D can't belong to a world multiple times nor can it belong to multiple worlds.

Navigation

[0] Message Index

[#] Next page

Go to full version