我创建了这个对象,其中包含对其他一些对象的引用:
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()
方法,以便null
在完成使用ListHandler
.
有必要吗?我是否需要清除所有对象以便稍后将它们垃圾收集起来,或者 GC 是否会知道该对象不再使用,因为初始化它的对象不再使用?