I know that with WeakReference , if I make WeakReference so that if there is no direct link to it, that it will be garbage collected with the next GC loop. My question becomes, what if I make an ArrayList from WeakReference s?
For example:
ArrayList<WeakReference<String>> exArrayList; exArrayList = new ArrayList<WeakReference<String>>(); exArrayList.add(new WeakReference<String>("Hello"));
Now I can access the data using exArrayList.get(0).get() .
My question will be: This is WeakReference data, will the data located in exArrayList.get(0) be GC'd with the next GC loop? (even if I donβt make another direct link to it), or will this particular link stick until the ArrayList is empty? ( exArrayList.clear(); : exArrayList.clear(); ).
If this is a duplicate, I have not found it with my google keywords.
java garbage-collection android arraylist weak-references
codingNewb
source share