When is a Java local variable eligible for GC?

前端 未结 6 1449
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 01:11

Given the following program:

import java.io.*;
import java.util.*;

public class GCTest {

    public static void main(String[] args) throws Exception {
             


        
6条回答
  •  时光取名叫无心
    2021-01-06 01:52

    In theory Test must not be in the scope since it is at the method level run() and the local variables should be garbage collected as you come out of the method.However you are storing the results in list, and i have read it somehere that lists are prone for storing weak references that are not garbage collected easily (depending on jvm implementation).

提交回复
热议问题