News for hackers. Stuff that matters.
Re:On Android, Garbage Collection Can Kill You by ajross on Monday June 25, 2012 @12:08PM (#4157140)
FTA: "A quick look at the output from ddms shows I was allocating tens of thousands of Colour, Vector2 and Vector3 objects per image"

And this is the fault of the garbage collector? Doing per-primitive ops by allocating heap blocks is a disaster, sorry. No one doing HPC does that. This won't run well anywhere, though obviously a desktop machine is going to give you a lot more freedom before you see frame rate problems.

Re:On Android, Garbage Collection Can Kill You by kevingadd on Monday June 25, 2012 @12:15PM (#4157177)
It's the fault of the garbage collector because the JVM provides no sane alternative (like, say, structs, or packed object arrays...).

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.

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.
Re:On Android, Garbage Collection Can Kill You by soc88 on Monday June 25, 2012 @02:09PM (#4157748)
Could you please tell me in which alternative reality you live in? :-)
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?
Re:On Android, Garbage Collection Can Kill You by mwd_ on Monday June 25, 2012 @01:50PM (#4157641)
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.

Re:On Android, Garbage Collection Can Kill You by ww520 on Wednesday June 27, 2012 @03:21AM (#4165944)
Didn't people do all that before the advent of GC? People seemed to manage resources just fine.
Re:On Android, Garbage Collection Can Kill You by astrodust on Monday June 25, 2012 @01:15PM (#4157471)
In garbage collected languages you really need to keep track of how much garbage you create. I've seen too many examples of people creating objects they really don't need in loops when they could recycle a single one for the entire procedure.