Proper way to remove a component

Have jReality programming problems or questions? Post them here.
Post Reply
tiofredo
Posts: 40
Joined: Mon 2. May 2011, 15:04

Proper way to remove a component

Post by tiofredo » Fri 24. Jun 2011, 15:07

Hi all.
Here's the situation :
I have my rootNode with two children : geometryNode and cameraNode.
geometryNode has n boxComponent, each one having a geometry and appearance.
cameraNode has n cameraComponent, each one having a camera, a sceneGraphPath referencing both, a viewer referencing the sgp and referenced in a renderTrigger, and a JFrame using viewer's resources.

I was wondering if geometryNode.removeChild(boxComponent), as cameraNode.removeChild(cameraComponent), were the proper way to get rid of a box or a camera.
I can remove the viewer from the renderTrigger, and dispose the JFrame I guess.
But would that be enough to really release the objects and the memory ?
Thanks for the help

ted
Posts: 57
Joined: Wed 25. Jul 2012, 22:53

Re: Proper way to remove a component

Post by ted » Fri 3. Aug 2012, 04:18

No guarantees, but you could do a test to check for memory leaks by monitoring freeMemory()
1. check a = freeMemory()
2. construct your structure
3. check b = freeMemory()
4. remove your structure
5. call gc() // not guaranteed to do anything, unfortunately
6. Check c = freeMemory()
7. Repeat until you have confidence in the results.

Note that gc is nondeterministic, so it may not do anything even when there's lots of memory ready to be reclaimed, unless it's near the limit where it has to do something to avoid running out of memory completely. You can run it overnight and graph the 3 variables a,b,c vs time (unless it runs out of memory, then you already know your answer).

Post Reply