I am somewhat familiar to Java, but am using it more now for Android.
Anyway, I’m kind of wondering if the only way to instantiate a class variable in Java is to allocate it onto the heap.
For instance:
[C++ Land]
Foo foo;
foo.doSomeAwesomeStuff(9001);
[Java Land]
Foo foo = new Foo();
foo.doSomeAwesomeStuff(9001);
This kind of irks me because there are some things in Java where I just want a temporary variable like a placeholder Matrix, but I don’t want to waste the system’s heap by throwing garbage onto it.
I feel like this might be a call for the android-ndk then, but that feels too much like overkill.
The latter. :\
The HotSpot JIT compiler automatically tries to do this escape detection to a small extent, when it can detect that a stack allocation is safe, but you cannot control it in general — you can only allocate on the heap.