java - Nested loop causing massive Garbage collection in android? -


i have piece of code in android, causing massive logs of gc

    // when turning frequency domain we'll need complex numbers:     byte audio[] = out.tobytearray();  //approx size 827392     int amountpossible = 200;     complex[][] results = new complex[amountpossible][];      // chunks:     (int times = 0; times < amountpossible; times++) {         complex[] complex = new complex[4096];         (int = 0; < 4096; i++) {             // put time domain data complex number imaginary             // part 0:             complex[i] = new complex(audio[(times * 4096) + i], 0);         }         // perform fft analysis on chunk:         results[times] = fft.fft(complex);     } 

below few of logs

    d/dalvikvm(10602): gc_concurrent freed 805k, 88% free 3911k/31075k, paused 2ms+5ms      d/dalvikvm(10602): gc_concurrent freed 1796k, 88% free 3957k/31075k, paused 1ms+2ms      d/dalvikvm(10602): gc_concurrent freed 1811k, 88% free 3970k/31075k, paused 1ms+3ms     d/dalvikvm(10602): gc_concurrent freed 1711k, 87% free 4102k/31075k, paused 2ms+3ms     d/dalvikvm(10602): gc_concurrent freed 1806k, 87% free 4138k/31075k, paused 1ms+3ms     d/dalvikvm(10602): gc_concurrent freed 1755k, 87% free 4226k/31075k, paused 1ms+3ms     d/dalvikvm(10602): gc_concurrent freed 1827k, 87% free 4242k/31075k, paused 1ms+3ms     d/dalvikvm(10602): gc_concurrent freed 1732k, 87% free 4258k/31075k, paused 2ms+2ms     d/dalvikvm(10602): gc_concurrent freed 1714k, 86% free 4387k/31075k, paused 1ms+3ms 

thanks in advance

your problem in java, complex heap-allocated java object. believe immutable, new complex instances must made each , every calculation. makes working math on complex numbers extremely slow , allocate large amount of memory. should avoided whenever possible.

the solution in pure java not use built-in complex type, , instead fft directly on pairs of double arrays, 1 each real , imaginary parts. alternatively, 1 can use single array containing both real , imaginary parts, though comments this question imply first approach tends give better performance. lack of non-heap-allocated objects unfortunate limitation of jvm.

for higher performance, best approach use native library. 1 option ffts, bsd licensed , comes jni bindings. uses run-time code generation , simd instructions achieve performance far higher pure-java library can.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -