在arrayList中添加值時,我得到「線程中的異常」主「java.lang.OutOfMemoryError:Java堆空間」異常。這只是一個例子「java.lang.OutOfMemoryError:Java堆空間」將元素添加到數組中
public class Test {
public static void main(String[] args)
{
Test t= new Test();
ArrayList<ArrayList<String>> deleteError = new ArrayList<ArrayList<String>>();
for(TableItem item : items) // loop moves 800 times
{
for(String Element_ID : checkelementID) // another loop which check element ids which moves for 800 again
{
t.deleteErrorInArrayList("1", "GEN_err", "11", deleteError);
t.deleteErrorInArrayList("1", "Greater_than", "11", deleteError);
t.deleteErrorInArrayList("1", "GEN_err", "16", deleteError);
t.deleteErrorInArrayList("1", "Greater_than", "16", deleteError);
}
}
}
public void deleteErrorInArrayList(String rowID,String message,String column,ArrayList<ArrayList<String>> mainlist)
{
ArrayList<String> list = new ArrayList<String>();
list.add(rowID);
list.add(message);
list.add(column);
mainlist.add(list);
list = null;
}
}
請幫助我。如何優化以上代碼,這樣我就可以減少時間並消除異常。
可能重複的[java.lang.OutOfMemoryError:Java堆空間](http://stackoverflow.com/questions/1596009/java-lang-outofmemoryerror-java-heap-space) –