gpt4 book ai didi

java - 我怎样才能清除不断增长的堆?

转载 作者:行者123 更新时间:2023-11-29 08:09:09 26 4
gpt4 key购买 nike

我有一个项目,它通过单击来演示 ImageViews 和它们的动画。它被实现为带有 go_in 和 go_out 动画的 ViewFlipper。每个 ImageView 都以 XML 的形式显示在每张演示文稿的幻灯片中。应用程序是为 Android 3.0 及更高版本的标签制作的。堆的大小随着每次切换而增长,logcat 看起来像(在 dalvik 给出错误之前: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

那么,问题是——如何清空堆或重新启动应用程序?或者如何组织不给它增加堆的应用程序?

这是我使用的代码

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

最佳答案

请使用以下代码,

BitmapFactory.Options bfOptions=new BitmapFactory.Options();
bfOptions.inDither=false; //Disable Dithering mode
bfOptions.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
bfOptions.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
bfOptions.inTempStorage=new byte[32 * 1024];
CameraTricks.SdCardImage= BitmapFactory.decodeFile(CameraTricks.yu,bfOptions);

CameraTricks.yu 是我的位图之路

关于java - 我怎样才能清除不断增长的堆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9390805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com