On Android, Garbage Collection Can Kill You
war-worlds.com
war-worlds.com
Synchrony issues occur when sharing an object pool among multiple threads. If you're sharing an object pool and using an unsafe data structure you will run into concurrent modification exceptions. Another issue could also be that using a thread safe data structure (or more simply a syncrhonized method) will lead to huge performance degradations because it is a central point of contention. A third issue with object pools is that if you have multiple threads using an object pool it might fill up your entire heap with cached objects.
The lifecycle issues come into play when you ask the question, "Who returns the object to the pool?" For example you could have 1 thread passing an object to another thread and then returning the object to the pool. If not considered you could run into a possibility where 2 different threads are operating on an object as if they are the sole owners leading to unexpected results.
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.
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.
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.
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.
Over Quota This application is temporarily over its serving quota. Please try again later.
is all I get right now from the link.
Clojure has a similar problem: works fine on desktop JVMs, but even initialising it takes many seconds on Dalvik.
Functional programming style tends to generate lots and lots of objects which die very young. Garbage collectors must be tuned for that. At least they should be generational. Mayhaps Dalvik's current GC is not?
Well, there is a lot of Scala code out there doing exactly that.
HotSpot has no problems with short-lived objects in pretty much all its garbage collectors while Dalvik's GC is just a lot less sophisticated and mature.
So I mainly agree with you, but the proposition of
Language allows producing lots of short-lived objects
+ Dalvik sucks
------------
Programs in that language have to be slow
doesn't hold in my opinion, as seen in the differences between Scala and Clojure.I talked about specific examples that I don't even know of. I don't know Scala enough to know whether non-destructive updates are the default. Are they? What about the core libraries?
I agree your proposition in fixed width font does not hold. I was merely asserting this one:
Program P produces lots of short-lived objects
+ Dalvik sucks (or is tuned for long lived-objects)
-------------------------------------------------
Program P have to be slowClojure just assumes the JVM can deal with it, and desktop ones do just fine, hence why no one noticed.
In short, mobile devices are different than laptops/desktops. If you threat them same, your application will suck.
If you don't stop misbehaving and start running my code correctly I'll ((forget to take you out of my pants pocket on laundry day)|(see just how far that hinge will bend)|(take you to the landfill))
None of these work BTW.
Edit: Sorry
If you're hitting slowdowns after initialization, there's a good chance it's reflection, not garbage collection. Type hinting can help if that is the case.
Because of the way that Clojure reuses immutable data structures, it doesn't do as much garbage collection as one might think.
public int hashCode() {
return new Double(x).hashCode() ^ new Double(y).hashCode();
}
does not seem to have the requisite understanding of how things to work to declare the inferiority of a widely used garbage collector.Out of curiosity, what language background are you coming from that this isn't obvious?
The constructor for Double is:
Double(double value)
I thought only 'Double' had the class methods, not 'double'.