| > "new Object()" takes up 16 bytes .... Only in JVMs and AOT compilers that don't do escape analysis. Also don't forget Smalltalk, which also only does references, was running in the Alto, Dolphin, and Dorado workstations. For example the Dorado was: - 128-512 kB - 606x808 pixels - 4 74181 CPUs So how does that compare to a beefy Android device? Also J2ME and Embedded Java are running quite well in many embedded platforms, in a few hundred KB steering soft real time systems like robots and missile radar controls. So yes, Java might not offer all the memory control features that other GC enabled languages do, going back to Algol 68, Mesa/Cedar, Eiffel, Modula-3, .... But given the performance of commercial JVM vendors, I would say Google has a lot of blame as well. EDIT: Forgot to add that when Java 10 comes out with value types and reified generics (according to the roadmap) this will become a moot point, except of course for Android Java given Google's unwillingness to provide support for the real thing. |
https://docs.oracle.com/javase/specs/jls/se8/html/jls-12.htm...
"Whenever a new class instance is created, memory space is allocated for it with room for all the instance variables declared in the class type and all the instance variables declared in each superclass of the class type, including all the instance variables that may be hidden (ยง8.3)."
Doesn't seem to allow for escape analysis eliminating the object. Plus escape analysis wouldn't really save you. These are class instances, you pretty much have to declare them before the scope you use them in, if you're using them in the condition of a while loop (which would be the way to use them).
I seem to have this experience in practice. If you have a value type and loop over it, creating a "dummy" instance of it outside of the loop, then erase and reset it's inner state on every loop iteration is far faster than creating an instance inside the loop. So I don't think escape analysis optimizes this case.