【发布时间】:2013-03-28 14:05:56
【问题描述】:
我创建了这个对象,其中包含对其他一些对象的引用:
public class ListHandler {
private AppVariables app; //AppVariables instance
private Extra extra; //the extra argument represanting the list
private ArrayList<FacebookUser> arrayList; //the array list associate with the list given
private Comparator<FacebookUser> comparator; //the comparator of the list
private String emptyText; //list empty text
/**
* Constructor - initialize a new instance of the listHandler
* @param app the current {@link AppVariables} instance
* @param extra the {@link Extra} {@link Enum} of the list
*/
public ListHandler(AppVariables app, Extra extra)
{
this.app = app;
this.extra = extra;
//set the array list to match the list given in the arguments
setArrayList();
setComparator();
setEmptyTest();
}
/**
* Clear all resources being held by this object
*/
public void clearListHandler()
{
this.arrayList = null;
this.comparator = null;
this.app = null;
this.emptyText = null;
this.extra = null;
}
我已经构建了clearListHandler() 方法,以便在使用完ListHandler 后将我正在使用的所有对象设置为null。
有必要吗?我是否需要清除所有对象以便稍后将它们作为垃圾回收,或者 GC 是否会知道该对象不再使用,因为初始化它的对象不再使用?
【问题讨论】:
标签: android memory-management garbage-collection