The Java Unsafe class allows you to allocate memory for an object as follows, but using this method, how would you release the allocated memory when you finish, since it did not specify the memory address ...
Field f = Unsafe.class.getDeclaredField("theUnsafe");
Is there a way to access the memory address from an object reference, maybe the integer returned by the hashCode implementation by default will work, so you can do ...
unsafe.freeMemory(p.hashCode());
doesn't seem right like ...
source share