Book Image

LibGDX Game Development By Example

By : James Cook
Book Image

LibGDX Game Development By Example

By: James Cook

Overview of this book

Table of Contents (18 chapters)
LibGDX Game Development By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The how, what, and why of object pools


Object pooling is the principle of reusing inactive or "dead" objects, instead of creating new objects every time.

-https://github.com/libgdx/libgdx/wiki/Memory-management#object-pooling

I guess the best place to start is to talk about what an object pool is. An object pool is a pool of objects, bet you didn't see that coming, that can be reused after they become inactive. The pool can either be prefilled or filled on demand; hopefully, when you require one of these objects, there will be a "free" one available.

I suppose you are now wondering why you would want to do this. I suspect you are wondering, "Hey, I can just call "new" to create an object; perhaps it is an acorn sprite you are creating, and I can do this as much as I want and I don't see an impact." Perhaps, on the scale we are working on, you might get away with that. However, it isn't a mindset you should really adopt here. You have to remember that one of the wonderful things with LibGDX...