java.lang.OutOfMemoryError Android - 大数组

时间:2016-03-09 13:44:53

标签: android arrays memory-management out-of-memory

我是Android开发的新手,请帮我解决错误。

我正在阅读wav文件并进行处理以与其他wav文件进行比较。我得到OutOfMemoryError并假设它可能是由于大数组。 这是我的processing()方法:

public void processing2(){
    System.out.println("reading in the file  .... ");
    float[] arr1 = readWav1("sink1.wav");
    float[] arr2 = readWav1("think1.wav");
    System.out.println("arr1 size: "+arr1.length);
    System.out.println("arr2 size: "+arr2.length);

    System.out.println("preprocessing .... ");
    FeatureVector a = extractFeatureFromExtractedAmplitureByteArray(arr1);
    FeatureVector b = extractFeatureFromExtractedAmplitureByteArray(arr2);

    System.out.println("vector a num of frames: " + a.getNoOfFrames());
    System.out.println("vector b num of frames: "+b.getNoOfFrames());

    //converting to 1d array
    flattened1 = twoDimToOne(a.getFeatureVector());
    flattened2 = twoDimToOne(b.getFeatureVector());

    System.out.println("1d array1 size: "+flattened1.length);
    System.out.println("1d array2 size: "+flattened2.length);

    System.out.println("DTW .... ");
    d = new DTW(flattened1, flattened2);
    System.out.println(d);
}

这是logcat:

System.out: reading in the file  .... 
System.out: File reading in progress..
System.out: File reading in progress..
System.out: arr1 size: 73750
System.out: arr2 size: 65558
System.out: preprocessing .... 
System.out: noOfFrames       110  samplePerFrame     512  EPD length   28556
System.out: noOfFrames       100  samplePerFrame     512  EPD length   25872
System.out: vector a num of frames: 110
System.out: vector b num of frames: 100
System.out: 1d array1 size: 4290
System.out: 1d array2 size: 3900
System.out: DTW .... 
dalvikvm-heap: Clamp target GC heap from 131.007MB to 128.000MB
dalvikvm-heap: Clamp target GC heap from 134.938MB to 128.000MB
dalvikvm-heap: Forcing collection of SoftReferences for 31216-byte allocation
dalvikvm-heap: Clamp target GC heap from 134.938MB to 128.000MB
dalvikvm-heap: Out of memory on a 31216-byte allocation.
…
AndroidRuntime: FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at java.lang.reflect.Array.createMultiArray(Native Method)

感谢。

1 个答案:

答案 0 :(得分:0)

在manifest.xml应用程序标记中添加 android:largeHeap =" true"

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"/>
相关问题