While working on a game project for Android i was digging for some information on performance optimization for game code. And i came to know that use of Java Collections like List,Arraylist etc are not encouraged in game codes,though collection is an useful tool in Java programming.Why is it so? I would like to know technical details as how much impact can Collection framework have on Android systems and why? Any help in this regard will be great.
It's mostly about memory allocation and garbage collection. Memory allocations during runtime gives your garbage collector a chance to bring out the trash. Which hurts your performance. GC should happen as seldom as possible.
Most java collections:
A) Allocate more memory than they need.
B) Allocate memory when you don't want them to.
C) Allocate memory for each iterator when iterating through a collection.
To circumvent these things:
A) Allocate collections with fixed sizes. ie. create object pools.
B) Allocate these pools at program init.
C) Avoid the for( Object obj : collection ) for those collection types that has a size() and a .get(int index) method.