www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: raft on December 13, 2010, 06:47:49 pm

Title: memory and gc
Post by: raft 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 (http://android-developers.blogspot.com/2009/02/track-memory-allocations.html) 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
Title: Re: memory and gc
Post by: EgonOlsen 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... ???
Title: Re: memory and gc
Post by: EgonOlsen 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 (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 (http://www.jpct.net/download/beta/jpct.jar)
Title: Re: memory and gc
Post by: raft 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.

Title: Re: memory and gc
Post by: EgonOlsen on December 13, 2010, 10:39:23 pm
getWorldTransformation() might, but getWorldTransformation(<Matrix>) should actually not. Have you tried that method instead?
Title: Re: memory and gc
Post by: raft 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
Title: Re: memory and gc
Post by: EgonOlsen 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... ???
Title: Re: memory and gc
Post by: raft 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 ;)
(http://img258.imageshack.us/img258/6941/screenshotdebugeclipse.png)
Title: Re: memory and gc
Post by: EgonOlsen 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...
Title: Re: memory and gc
Post by: raft 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.