Java - Can objects which are executing methods be garbage-collected?

后端 未结 3 1981
春和景丽
春和景丽 2020-12-15 20:47

In Java, I\'ve done things like the following without thinking much about it:

public class Main {

    public void run() {
        // ...
    }

    public s         


        
3条回答
  •  轮回少年
    2020-12-15 21:23

    If an object method is being executed, it means someone is in possession of that reference. So no, an object can't be GC'd while a method is being executed.

提交回复
热议问题