Re:On Android, Garbage Collection Can Kill You
by ww520 on Monday June 25, 2012 @01:20PM
(#4157499)
Why not just pre-allocate the objects and reuse them?
[ Parent
| on HN ]
This is what I do for Android games -- design things to be mutable and pre-allocate however many I'll need during a level. You also have to avoid foreach because it creates objects.
This is an area where C# is better. You can create classes or structs and structs go on the stack. Structs are a lot more appropriate for objects like rects.
Re:On Android, Garbage Collection Can Kill You
by kevingadd on Monday June 25, 2012 @02:57PM
(#4158076)
Have fun getting that pattern right by hand. The language isn't doing anything to help you.
Make sure you release the instances back to the pool on every exit path, but don't release them if you let a reference escape into another scope.
Have fun debugging the issues that crop up when you accidentally release an instance that's still being used back into the pool.
Have fun hunting down that one code path that isn't returning instances to the pool, and as a result is draining the pool down to 0 and causing you to gain nothing from it.