Android Studio-旋转设备导致越来越多的内存被使用 [英] Android Studio - Rotating device causes more and more memory to be used

查看:140
本文介绍了Android Studio-旋转设备导致越来越多的内存被使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Android Studio项目,用于测试一些小的代码段.今天,当我摆弄一些代码时,我注意到每次旋转设备时,都会导致应用程序使用越来越多的内存.图表的屏幕截图如下:

I have this simple Android Studio project for testing out little code snippets. Today while I was fiddling around with some code, I noticed that each time I rotate my device, it causes the app to use more and more memory. Screenshot of the chart is as follows:

每次旋转设备时,分配的内存会增加,可用内存量会减少.当可用内存为零时,它将清除一部分内存,但不是全部.随着我不断来回旋转设备,最终会导致更多可用内存可供应用程序使用,并且分配的内存不断增加.

Each time I rotate the device, allocated memory increases and free memory amount decreases. When free memory hits zero, it cleans a chunk of memory, but not all. As I keep rotating device back and forth, eventually it causes more free memory made available to the app, and allocated memory keeps increasing and increasing.

这是一个简单的应用程序,只有一个TextView,根本没有执行代码.没有数据库活动,没有网络活动,没有游标,什么也没有引起任何内存泄漏.

This is a simple app with only single TextView and no execution code at all. No database activity, no network activity, no cursor, nothing to cause any memory leak whatsoever.

这是MainActivity.java的内容:

Here is the MainActivity.java content:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
}

我试图转储Java堆,但对我来说看起来却毫无用处.

I tried to dump the java heap, but it looks all jibberish to me.

这是预期的行为吗?实际上是什么填满了内存?到底是怎么回事?

So is this the expected behavior? What is actually filling up the memory? What is going on?

推荐答案

如果这是您的MainActivity,那么您就不会出现内存泄漏.

If that is your MainActivity then you don't have memory leaks.

但是,如果要确保内存监视器中有一个名为Initiate GB的按钮.单击它,它将运行垃圾收集器以释放您未使用的引用.

But, if you want to be sure there is a button in the memory monitor called Initiate GB. Click it an it will run the Garbage Collector freeing up your unused references.

执行此操作时,您会看到内存下降到其初始数量.

You will see that memory drops to its initial amount when doing that.

这篇关于Android Studio-旋转设备导致越来越多的内存被使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆