Author Topic: why world.removeObject not destroy object3D?  (Read 708 times)

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
why world.removeObject not destroy object3D?
« on: April 24, 2015, 04:26:21 am »
When i use world.removeObject(obj),and later use world.addObject(obj),the obj  is still there.

i thought removeobject() will clear object from memory,in fact i am wrong?

so,if i want to destroy obj,i just use,
obj.clearobject();
obj.clearrotation();
obj.cleartranslation();
obj=null;


is that right?

in a shorting say,if i want destroy a object3D,which method will free memory,and really set the obj clear?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: why world.removeObject not destroy object3D?
« Reply #1 on: April 24, 2015, 06:52:44 am »
The object will be unloaded from GPU and CPU memory if there's no further reference in your code to it. In this example, setting it to null should do it unless there's some others reference to it. You can skip these clear....-methods though. They are just resetting the matrix.
« Last Edit: April 24, 2015, 07:33:29 am by EgonOlsen »

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: why world.removeObject not destroy object3D?
« Reply #2 on: April 24, 2015, 11:41:25 am »
with DDMS,set object3d to null,later memory will be freed.
but world.removeobject(obj),memory never freed.


ok,i think set to null,it was the best method to destroy Object3D.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: why world.removeObject not destroy object3D?
« Reply #3 on: April 24, 2015, 12:25:08 pm »
but world.removeobject(obj),memory never freed.
No. Why should it? The world is essentially a set of objects. As long as you keep a reference to an instance, nothing will be freed. That's how Java works...