Re:On Android, Garbage Collection Can Kill You
by ajross on Monday June 25, 2012 @12:20PM
(#4157206)
Which is one reason that no one does HPC (or related tasks, like image processing) in Java. To be fair: Android has a nifty NDK that works very well for tasks like this.
Could you please tell me in which alternative reality you live in? :-)
Why not just pre-allocate the objects and reuse them?
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.
If there's Only One Way To Do It, that One Way should not cause the garbage collector to fall over and choke. It sounds like the desktop JVM handles it just fine, in comparison.