I have some data structures, and I would like to use one as a temporary, and another as not temporary.
ArrayList<Object> myObject = new ArrayList<Object>();
ArrayList<Object> myTempObject = new ArrayList<Object>();
//fill myTempObject here
....
//make myObject contain the same values as myTempObject
myObject = myTempObject;
//free up memory by clearing myTempObject
myTempObject.clear();
now the problem with this of course is that myObject
is really just pointing to myTempObject
, and so once myTempObject
is cleared, so is myObject
.
How do I retain the values from myTempObject
in myObject
using java?
List.addAll
. But if you need to retain all the objects then clearing the temp list is not really going to clear a whole lot of memory. Because your are only trying to clear the references, as far as objects you are trying to keep them. – Iene