在安卓工作室的日志中等待封堵GC Alloc

问题描述 投票:0回答:1

我有一个相当大的双数组,有1,71,00,000个元素。我需要遍历这个数组,将数组切成10k点的小数组,然后将剩余的点(如果有的话)放入最后一个切片。

我有一个基本的代码。

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;
    }

它的输出结果如下

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

当我用小得多的数组做同样的操作时,输出不是这样的。为什么会显示"等待阻塞的GC分配"和这些信息?是严重的问题吗?JVM问题还是我的逻辑错误?

java android arrays jvm heap
1个回答
0
投票

使用 android:largeHeap="true"在我的manifest.xml中解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.