我有這個目標我已經創建持有引用到一些其他對象:Android我是否需要將每個對象設置爲null時完成使用它?
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;
}
時使用ListHandler
完我已經建立了clearListHandler()
方法,以我使用的所有對象設置爲null
。
有必要嗎?我是否需要清除所有對象以便稍後收集它們垃圾,否則GC會知道此對象已不再使用,因爲已初始化它的對象不再使用?
Oracle與Android無關。這裏是[Dalvik](http://en.wikipedia.org/wiki/Dalvik_(software))。 – 2013-03-28 14:37:48
但Android仍然是Java,而Dalvik只是另一個JVM。鏈接解釋了任何VM/JVM常見的GC基礎知識。 –
〜「**垃圾收集器將自動確定**」。從什麼時候垃圾收集器可預測和可靠?特別是在Android上... –