How to free memory using Java Unsafe, using a Java reference? -
How to free memory using Java Unsafe, using a Java reference? -
java unsafe class allows allocate memory object follows, using method how free memory allocated when finished, not provide memory address...
field f = unsafe.class.getdeclaredfield("theunsafe"); //internal reference f.setaccessible(true); unsafe unsafe = (unsafe) f.get(null); //this creates instance of player class without initialization player p = (player) unsafe.allocateinstance(player.class); is there way of accessing memory address object reference, maybe integer returned default hashcode implementation work, do...
unsafe.freememory(p.hashcode()); doesn't seem right how...
"memory address" of object reference not create sense since objects can move across java heap. you cannot explicitly free space allocated unsafe.allocateinstance, because space belongs java heap, , garbage collector can free it. if want own memory management outside java heap, may utilize unsafe.allocatememory / unsafe.freememory methods. deal raw memory addresses represented long. memory not java objects.
java memory-management jvm directmemory
Comments
Post a Comment