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/nonotan Dec 21 '14

I don't understand what you mean. Pooling = reusing. I don't know what you could mean by "pathologically worst case" -- if you don't allocate anything whatsoever during gameplay, your GC shouldn't do anything (unless it's buggy). It sounds like a problem with your specific implementation of pooling.

1

u/zuurr Dec 21 '14

It's not a problem with my implementation, trust me, I worked on GCs in graduate school.

Basically the issue is that it will still try to do garbage collections, but they'll take much longer because you have so many unused objects in your pool.