There will be a OOM error in creating so many Strong Reference is because of GC won't collect Strong Reference, but GC will collect Weak Reference if there no extra memory. So my question is :
I create a loop to create Weak Reference while I set my -Xmx2M
Set<SoftReference<Integer>> sa = new HashSet<~>();
for (int i = 0; i < size; i++) {
SoftReference<Integer> ref = new SoftReference<Integer>(i);
sa.add(ref);
}
It's still occur OOM, Why?