I have a pretty large double array of say 1,71,00,000 elements. I need to traverse through the array, slice the array in smaller arrays of 10k points each and the remaining points(if any) into the last slice.
I have a basic code:
public static boolean getSliceOfArray(double[] arr,int slice_len)
{
//arr: big array
//slice_len: 10,000
System.out.println(arr.length);
int n_times=(arr.length/slice_len);
int i=0;
for(int n=0;n<n_times;n++)
{
Arrays.copyOfRange(arr,i,i+slice_len);
i=i+slice_len;
}
System.out.println(n_times);
if(i!=arr.length)
{
System.out.println( Arrays.copyOfRange(arr,i,arr.length).length);
}
return true;
}
It gives me following output:
I/System.out: 17100000
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 13.428ms
Starting a blocking GC Alloc
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 36.867ms
I/xample.styleap: Starting a blocking GC Alloc
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 26.012ms
Starting a blocking GC Alloc
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 32.625ms
Starting a blocking GC Alloc
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 21.645ms
Starting a blocking GC Alloc
I/System.out: 1710
When I do the same with considerably smaller sized array the output is not like this. Why does it show "Waiting for a blocking GC Alloc" and these messages? Is it a serious issue? JVM issue or my logic error?
Using android:largeHeap="true"
in my manifest.xml solved this issue.
Your Application is using too much Heap Memory(creating objects on the fly maybe and not getting Garbage collected) , and hence the Java GC is constantly trying to free up memory but it is not able to do it as your app is generating a lot of "leak". So basically your app memory requirements are increasing constantly and hence GC is warning you about it as it will eventually lead to a crash
You should:
System.gc() ( as suggested by someone earlier) will not help as you cant guarantee/force GC
Rather than using the flag to increase the Heap Size in JVM args, I would suggest improve/edit your own codebase first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With