Avoiding garbage collector in Android

Hi,

I am building a game for android that requires me to use a physics engine (I am using Phys2D). Before creating the physics world I get a frame rate of more than 60fps. Once I create the world and start it in the game loop I get a sharp decrease in the frame rate (drops to ~20). I think that the sharp decrease is due to the fact that the Garbage collector is working like crazy after the world is created.

Is there a way around it? is there some other way I can create the physics world without having the Garbage collector working all the time?

Thanks

Run ddms in the SDK tools directory (not through Eclipse). You can use the allocation tracker to see what garbage collection is going on.

I don’t have experience with Phys2D specifically.

Remember that those devices don’t have a fpu, so everything using floats (or doubles) will be quite slow. Maybe that’s the reason for your slowdown after enabling physics, which will most likely use floating point.

Could be either. Phys2D is float based but is also none to create alot of gargabe in the form of lots of tiny objects. On the desktop this doesn’t hurt too much (given the way GC works on small short lived objects) but on Android this is likely to cause alot of pain.

Have you considered JBox2D? Thats considered to have a lot of less garbage.

Kev

Before I implemented my own dirty-but-fast physics engine to my android game (which I will release in 2 weeks or so), I tried using Phys2D . I dont think the problem is the garbage collection, but the engine itself which is pretty acurrate, thus pretty processor consuming .
When I tried running Phys2D with just a few entities, I got barely 5 FPS on my HTC Hero, with most basic rendering.
Maybe I was doing something wrong, but I even tried reducing the number of steps, but no success .

@kevglass have u tried running your lib in Android? Do u think there’s a way it can run on it with a reasonable framerate?