When is a Java local variable eligible for GC?

前端 未结 6 1454
被撕碎了的回忆
被撕碎了的回忆 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:45

    Slightly off-topic, but finalize() should never be used to close() a file. The language does not guarantee that finalize() will ever get called. Always use a try ... finally construct to guarantee file closure, database cleanup, etc.

提交回复
热议问题