r/truegamedev • • Oct 29 '14

Is object pooling worthwhile?(Java, Android)

has anyone here implemented some form of object pooling for games in java?

did you find it was worthwhile?

I attempted to make my own but i have found it's introducing a lot of complexity almost entirely due to the need to set object types. http://stackoverflow.com/questions/19883211/libgdx-object-pool-for-many-objects-of-the-same-parent-class

Having to keep all the objects as one type i decided to make them all generic entities. They then get their properties from classes i've called "EntityTypes" on single instances of these EntityTypes exist but can be shared by multiple Entities.

So the only difference between a Planet Entity and a ship Entity would be the EntityType they happen to use, and other variables which contain an object3d , position , velocity etc.

This would be easier if i could extend the pool objects.

So now im thinking of having multiple pools http://stackoverflow.com/questions/13294757/using-object-pools-in-libgdx

tl;dr is object pooling worth it in java games?

7 Upvotes

27 comments sorted by

View all comments

Show parent comment

1

u/zuurr Dec 12 '14

This is an important point. Pooling can be worthwhile, but it's worth keeping in mind that it can cause pathologically bad behavior from the GC, especially when used on small POD types like Vector2,3,4, Color, etc. The solution for them is to reuse and not allocate many of them (or to switch to something with value types like C++).