Author Topic: memory and gc  (Read 4869 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
memory and gc
« on: December 13, 2010, 06:47:49 pm »
this is a bit annoying: according to my tests, the less objects you create, the less frequently dalvik garbage collects. but when it does, it collects many objects at once and hence the delay gets larger. kind of dilemma :-\ my gl thread's priority was 8, i left as default (5) but that didnt help.

anyway, inspecting memory allocations i've spot some methods. it may be worth improving them:
* Camera.lookAt creates a new Matrix all the time. instead using an instance field may help
* Camera.getPosition() is used frequently, so it may be worth adding a Camera.getPosition(SimpleVector) method

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: memory and gc
« Reply #1 on: December 13, 2010, 10:06:14 pm »
You are right...i'll change that. Actually, i though that i already had modified lookAt and i'm a bit confused why it isn't...must have been some other method then... ???

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: memory and gc
« Reply #2 on: December 13, 2010, 10:12:34 pm »
Uploaded a new jar that contains both fixes (untested...): http://www.jpct.net/jpct-ae/download/alpha/jpct_ae.jar

Edit: The beta jar of desktop jPCT has been updated with the new method too: http://www.jpct.net/download/beta/jpct.jar
« Last Edit: December 13, 2010, 10:14:45 pm by EgonOlsen »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: memory and gc
« Reply #3 on: December 13, 2010, 10:33:44 pm »
thanks for quick reply, both methods seems to run fine and very few objects are created now ;D
i will really appreciate if you add Camera.getPosition(SimpleVector) to desktop jPCT too.

Object3D.getWorldTransformation() seems to create a Matrix too but not as frequent as other method.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: memory and gc
« Reply #4 on: December 13, 2010, 10:39:23 pm »
getWorldTransformation() might, but getWorldTransformation(<Matrix>) should actually not. Have you tried that method instead?

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: memory and gc
« Reply #5 on: December 13, 2010, 10:42:01 pm »
i dont call that method. it's called by Object3D.transformVertices which in turn called by World.renderScene

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: memory and gc
« Reply #6 on: December 13, 2010, 10:48:25 pm »
I don't get it...there is no reference to getWorldTransformation() in transformVertices() according to Eclipse and according to my eyes (which doesn't mean much...). There is a call to getWorldTransformation(<Matrix>) for objects that have lazy transformations enabled, but that's all... ???
« Last Edit: December 13, 2010, 10:50:00 pm by EgonOlsen »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: memory and gc
« Reply #7 on: December 13, 2010, 10:56:21 pm »
allocation tracker does not display method signatures but only method names and line numbers. see below.

according to this getWorldTransformation(?) creates a Matrix via Matrix.cloneMatrix(). but as i said it's not that frequent.. it's ok ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: memory and gc
« Reply #8 on: December 13, 2010, 11:06:46 pm »
That should happen only once per object if the object uses lazy transformations. From there on, the created matrix should be recycled even when disabling lazy transformations for some time. The logic to support this is a bit twisted, so i may have overlooked something...

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: memory and gc
« Reply #9 on: December 13, 2010, 11:21:14 pm »
ok then no problem :) this allocation tracker thingy does not print how many times an object is created (at least i cant read it) it just prints some messages many times (number of times cant be creation count but maybe a proportion).  i can say this Matrix creation is relatively low as you said.