memory and gc

Started by raft, December 13, 2010, 06:47:49 PM

Previous topic - Next topic

raft

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

EgonOlsen

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... ???

EgonOlsen

#2
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

raft

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.


EgonOlsen

getWorldTransformation() might, but getWorldTransformation(<Matrix>) should actually not. Have you tried that method instead?

raft

i dont call that method. it's called by Object3D.transformVertices which in turn called by World.renderScene

EgonOlsen

#6
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... ???

raft

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 ;)

EgonOlsen

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...

raft

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.