本文介绍了如何清除堆成长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其工作方式与他们的动画ImageViews中通过单击presentation。它被实现为具有go_in和go_out动画ViewFlipper。每个ImageView的以XML为特色presentation的每张幻灯片。应用程序是与Android 3.0及更高版本的标签制作。堆大小增大每个开关和logcat的样子(之前的Dalvik给出了一个错误:OOF)...

  I / dalvikvm堆(5313):成长堆(frag的情况下),以205.584MB为3850256字节分配
D / dalvikvm(5313):GC_CONCURRENT释放0K,1%的自由210440K / 210759K,暂停2MS + 9ms的
I / MediaPlayer的(5313):$称为状态4 P $ ppareAsync
D / dalvikvm(5313):GC_FOR_ALLOC释放166K,1%的自由210478K / 210887K,暂停29ms
I / dalvikvm堆(5313):成长堆(frag的情况下),以209.293MB为3850256字节分配
D / dalvikvm(5313):GC_FOR_ALLOC释放< 1K,1%的自由214238K / 214663K,暂停为33ms
D / dalvikvm(5313):GC_CONCURRENT释放< 1K,1%的自由214238K / 214663K,暂停3毫秒+ 10ms的
D / dalvikvm(5313):GC_FOR_ALLOC释放4K,1%的自由214838K / 215303K,暂停为32ms
I / dalvikvm堆(5313):成长堆(frag的情况下),以213.551MB为3850256字节分配
D / dalvikvm(5313):GC_FOR_ALLOC释放0K,1%的自由218598K / 219079K,暂停为33ms
D / dalvikvm(5313):GC_CONCURRENT释放< 1K,1%的自由218598K / 219079K,暂停1毫秒+ 10ms的
I / MediaPlayer的(5313):$称为状态4 P $ ppareAsync
D / dalvikvm(5313):GC_FOR_ALLOC释放7K,1%的自由220438K / 220743K,暂停29ms
D / dalvikvm(5313):GC_FOR_ALLOC释放2K,1%的自由222253K / 222535K,暂停29ms
D / dalvikvm(5313):GC_FOR_ALLOC释放< 1K,1%的自由222634K / 222855K,暂停为33ms
I / dalvikvm堆(5313):成长堆(frag的情况下),以221.165MB为3850256字节分配

所以,问题是 - 怎么可能为null堆或重新启动应用程序?或如何组织应用程序不给它增加堆?

下面是code我用

  ImageView的buttonNext_13 =(ImageView的)findViewById(R.id.Button_next_13);
buttonNext_13.setOnClickListener(新View.OnClickListener(){
    @覆盖
    公共无效的onClick(查看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();
        返回;
    }
});
ImageView的按钮previous_13 =(ImageView的)findViewById(R.id.button_ preious13);
按钮previous_13.setOnClickListener(新View.OnClickListener(){
    @覆盖
    公共无效的onClick(查看view132){
        flipper.setInAnimation(AnimationUtils.loadAnimation(
            view132.getContext(),R.anim.go_ preV_IN));
        flipper.setOutAnimation(AnimationUtils.loadAnimation(
            view132.getContext(),R.anim.go_ preV_OUT));
        flipper.show previous();
        返回;
    }
});


解决方案

看来你正在泄漏内存。因此,解决办法是停止这样做。这里来硬的部分:实际停止泄漏内存。作为视图切换时内存的增长,最有可能的原因是你没有正确处理,同时启动和停止的观点引用。显示更多code,那么我们将能够帮助你。

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;
    }
});
解决方案

It seems that you are leaking memory. So the solution is to stop doing this. And here comes the hard part: actually stopping leaking memory. As memory grows during view switching, the most probably cause is that you do not handle references correctly while starting and stopping views. Show more code, then we will be able to help you

这篇关于如何清除堆成长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 11:20