Java reference variable management? -


i want understand exact management of reference variables in java. how memory management them? how memory reference variable takes of 32 bit or 64 bit operating system.

what 2 of following code? better based on above questions

creating reference variable 1 , assigning new objects (flyweight pattern guess ??).

    stringbuilder strreference = null;      for(int = 0;i < 1000000; ++) {         strreference = // assiging object somewhere db list         // doing operation on object strreference     } 

nowcreating reference variable everytime in the

        for(int = 0;i < 1000000; ++) {             stringbuilder strreference = // assiging object somewhere db list             // doing operation on object strreference         } 

can see exact effect of above 2 code statements profiler ?

the exact size of reference not mandated java specifications (you can see mandated here). size dependent on java virtual machine implementation, , in system can of 32bits, in other 64bits.

about sample code, both same jvm (see footnote #1 nonetheless). remember space variables created inside functions kept in stack , before entering function jvm make room variable (strreference). source: here.

so not where/how create references where/how create data inside references.

if want see more, try compiling code , using javap see generated bytecode. way can see if implementation changes.


footnote #1: first 4 variables/parameters/this in each method have special management inside bytecode, there can difference in case if declare reference in code. difference size , speed of bytecode 4 first variables have special "opcodes" them.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -