I'm a C++ programmer entering the world of Java. And I cannot get rid of the bad feeling of having to let the Java garbage collector do my cleaning.
How, for example, will this code behave in Java?
public void myFunction() {
myObject object = new myObject();
object.doSomething();
}
Will the local variable object be deleted when myFunction() exits?
Do I have to set object to null before exiting, or will it be out of scope and be deleted by the GC? Or, at worst, will it leak like it would in C++?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…