I have a project which works as a presentation of ImageViews with animation of them by clicking. It is realized as a ViewFlipper with go_in and go_out animation. Each ImageView is featured in XML for each slide of presentation. App is made for tabs with Android 3.0 and higher. Size of heap grows with each switching and logcat looks like (before dalvik gives an error: oof) ...
I/dalvikvm-heap(5313): Grow heap (frag case) to 205.584MB for 3850256-byte allocation
D/dalvikvm(5313): GC_CONCURRENT freed 0K, 1% free 210440K/210759K, paused 2ms+9ms
I/MediaPlayer(5313): prepareAsync called in state 4
D/dalvikvm(5313): GC_FOR_ALLOC freed 166K, 1% free 210478K/210887K, paused 29ms
I/dalvikvm-heap(5313): Grow heap (frag case) to 209.293MB for 3850256-byte allocation
D/dalvikvm(5313): GC_FOR_ALLOC freed <1K, 1% free 214238K/214663K, paused 33ms
D/dalvikvm(5313): GC_CONCURRENT freed <1K, 1% free 214238K/214663K, paused 3ms+10ms
D/dalvikvm(5313): GC_FOR_ALLOC freed 4K, 1% free 214838K/215303K, paused 32ms
I/dalvikvm-heap(5313): Grow heap (frag case) to 213.551MB for 3850256-byte allocation
D/dalvikvm(5313): GC_FOR_ALLOC freed 0K, 1% free 218598K/219079K, paused 33ms
D/dalvikvm(5313): GC_CONCURRENT freed <1K, 1% free 218598K/219079K, paused 1ms+10ms
I/MediaPlayer(5313): prepareAsync called in state 4
D/dalvikvm(5313): GC_FOR_ALLOC freed 7K, 1% free 220438K/220743K, paused 29ms
D/dalvikvm(5313): GC_FOR_ALLOC freed 2K, 1% free 222253K/222535K, paused 29ms
D/dalvikvm(5313): GC_FOR_ALLOC freed <1K, 1% free 222634K/222855K, paused 33ms
I/dalvikvm-heap(5313): Grow heap (frag case) to 221.165MB for 3850256-byte allocation
SO, the question is - how is it possible to null heap or restart the application? Or how organize the app not giving it to increase heap?
Here is the code I used
ImageView buttonNext_13 = (ImageView)findViewById(R.id.Button_next_13);
buttonNext_13.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view131) {
flipper.setInAnimation(AnimationUtils.loadAnimation(
view131.getContext(), R.anim.go_next_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(
view131.getContext(), R.anim.go_next_out));
flipper.showNext();
mp_file.release();
mp_file = MediaPlayer.create(getApplicationContext(), R.raw.theme);
mp_file.start();
return;
}
});
ImageView buttonPrevious_13 = (ImageView)findViewById(R.id.button_preious13);
buttonPrevious_13.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view132) {
flipper.setInAnimation(AnimationUtils.loadAnimation(
view132.getContext(), R.anim.go_prev_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(
view132.getContext(), R.anim.go_prev_out));
flipper.showPrevious();
return;
}
});