Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently working on a Java game I know a lot of games created all instances of objects beforehand and then bring then in and out of play when they are needed.

Will it be worth it to have a Vector of all instances that are alive, and loop through that instance of going through all of the instances and checking the alive boolean?


share|improve this question
up vote 3 down vote accepted

For simplicity, it's easier to have one vector/array that has all the objects that are alive. You don't want to check if they are alive in order to update them. That list represents the objects that need to be updated. Have a second vector/array, a stack if you will, that you add "dead" objects to once they are not needed for the time being. Once you need to reuse them simply pop them back into your vector that you're calling an update on.

If you're going by this approach might be interesting to read on object-pools

Of course you could also just remove them from memory and create new objects by instantiating them when needed. Eitherway, it's cleaner if you only hold your objects that actually need updating. All your objects that don't need to be updated( because they are inactive/dead) shouldn't be there.

share|improve this answer
The wiki link was very helpful, Thanks! – Fricken Hamster Jan 22 '13 at 4:55
@FrickenHamster if you are satisfied with my answer, please accept it. So it can be closed. – Sidar Mar 22 '13 at 16:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.