Java GC 内存删除

Java GC memory remove

我目前正在编写一个 java 套接字服务器,我想知道在下一种情况下会发生什么:

mainClass 创建 Lobby class 并将其添加到 mainClass[=33 中的数组=].

Lobby class 创建一个 Room class 并将其添加到 大堂class.

房间 class 持有对 大厅 class.

的引用

mainClass 从数组中删除 Lobby 实例

lobby hold reference to the room and the room hold reference to the lobby,他们会被gc清理吗?

如果您的对象没有来自 GC Roots 的某些引用,它们将被删除。