multithreading - java : When memory returns in method? -


i know memory returns after function ends.

when thread object returned? - when variable returned?

public  aaa () {       int = 1;      new thread() {              public void run() {               }     }.start(); } 

sorry.

when removed stack? after aaa() ends or thread ends?

when thread object removed heap?

i think "returned" poor choice of wording in question, , you're asking "when x removed heap?" - i.e. "when can memory allocated x reallocated else?"

if that's case, you're asking called garbage collection, ongoing process java finds things can't use anymore - "garbage" - , removes them memory.

simply put, something becomes "garbage" when becomes unreachable - when there no remaining references it.

to use example think you're alluding to:

void foo() {   int = 1;   //do stuff    return;  } 

each time foo() executes, memory space allocated new local variable a. each time finishes executing, there's no way can ever refer variable again, therefore becomes eligible garbage collection.


Comments