memory - Java: Best Practice for Declaration and Initialization -


i consider myself quite experienced in java there still minor basic things i'm not sure of.

i try write maintainable, easy readable code , aim highest efficency. example call "new"-operator when needed.

that because don't want allocate memory unnecessarily. supporting variables?

lots of people tend declare string assign long ass method call this:

string helper = class.method1().method2(param).getter();

i wonder if doesn't allocate more memory needed. getter returns new object , more memory allocated referencing in addition. when have use getter more once helper string convenient, if needed once wouldn't better pass method directly instead of declaring new variable? allocate memory heap?

object a, b, c, d, e ,f , g, h, i, j ...;

i hope more experienced java guys me can tell me how handle basic stuff this. thanks! :)

does allocate memory heap? no, allocated on stack. global variables allocated on heap.

when method finishes return allocated memoryspace took stack, , variable no longer of concern.

i wonder if doesn't allocate more memory needed allocate memory on stack reference variable. reference not needed if pass function argument. however, function still has evaluated , it's returned value will placed on stack. if declare variable it, few writes , reads has performed, should in cases not of concern respect todays efficient computers.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -