首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在java中销毁对象?

如何在java中销毁对象?
EN

Stack Overflow用户
提问于 2018-07-23 05:48:43
回答 2查看 0关注 0票数 0

我在接受采访时遇到了以下问题:

代码语言:txt
复制
a. System.gc();  
b. Runtime.getRuntime.gc();  
c. object.delete();  
d. object.finalize();  
e. Java performs gc by itself, no need to do it manually.
  1. 答案应该是E?
  2. 如果E不存在呢?那么?很明显,C不是对整个应用程序的答案。a和b将对整个应用程序进行GC(对一个对象需要问题)。所以我认为是d,因为final()是在GC之前调用的(但是在调用Finish GC之后有必要吗?)
EN

回答 2

Stack Overflow用户

发布于 2018-07-23 14:13:24

以下是代码:

代码语言:txt
复制
public static void main(String argso[]) {
int big_array[] = new int[100000];

// Do some computations with big_array and get a result. 
int result = compute(big_array);

// We no longer need big_array. It will get garbage collected when there
// are no more references to it. Since big_array is a local variable,
// it refers to the array until this method returns. But this method
// doesn't return. So we've got to explicitly get rid of the reference
// ourselves, so the garbage collector knows it can reclaim the array. 
big_array = null;

// Loop forever, handling the user's input
for(;;) handle_input(result);
}
票数 0
EN

Stack Overflow用户

发布于 2018-07-23 15:14:29

简短答案-E

答案是E考虑到其他选项显然是错的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档