Android应用内存泄漏

时间:2015-12-22 10:32:41

标签: java android memory android-studio crash

我正在制作应用程序,它差不多完成了。直到应用程序一直冻结,由于内存泄漏,或其他东西。有人有解决方法吗?哦是的,它在添加倒数计时器后发生了。以下是我的一些代码:'

 while(methodCounter<1){ new CountDownTimer(60000, 1000) {
//methodcounter is the amount of times the method is called
                public void onTick(long millisUntilFinished) {
                    Timer.setText("seconds remaining: " + millisUntilFinished / 1000);
                }

                public void onFinish() {
                    startActivity(new Intent(MainActivity.this, AlertDialogClass.class));
                }

            }.start();
            }`

这是我的一些logcat:

12-22 11:31:03.096 7109-7109/com.liammertensbe.com.typefaster D/dalvikvm: GC_FOR_ALLOC freed 3040K (77707), 39% free 4952K/8048K, paused 27ms, total 28ms
12-22 11:31:03.444 7109-7109/com.liammertensbe.com.typefaster D/dalvikvm: GC_FOR_ALLOC freed 3040K (77707), 39% free 4952K/8048K, paused 28ms, total 28ms
12-22 11:31:03.791 7109-7109/com.liammertensbe.com.typefaster D/dalvikvm: GC_FOR_ALLOC freed 3040K (77705), 39% free 4952K/8048K, paused 27ms, total 27ms
12-22 11:31:04.140 7109-7109/com.liammertensbe.com.typefaster D/dalvikvm: GC_FOR_ALLOC freed 3040K (77707), 39% free 4952K/8048K, paused 27ms, total 27ms

1 个答案:

答案 0 :(得分:0)

您的代码显示您并未尝试减少 methodCounter 变量。所以循环变得无限。这就是你的应用程序冻结的原因。

除此之外,您还应该在try和catch块中编写代码并处理 OutOfMemoryError