重启应用程序时Android堆增长

时间:2012-08-13 20:37:00

标签: android memory-management heap andengine

嗨,你好好读一下与android中的grow heap有关的错误

08-13 21:46:22.382: I/dalvikvm-heap(10859): Grow heap (frag case) to 20.578MB for 2400016-byte allocation

下面是日志(已过滤),其中我多次退出我的应用程序并一遍又一遍地重新开始。正如你可以看到的那样,每次重启都会增加堆。怎么可能?完全退出时,应该不会清除应用堆?

如果我对代码进行任何更改并重新启动应用程序,则堆将重置为其原始值。这种行为是否正常?

每次我在应用程序中切换活动时,也会发生相同的堆增长。我在andengine中编写了我的应用程序。我的堆高达80MB,加载速度更快,堆积更大。

I/dalvikvm-heap(13094): Grow heap (frag case) to 13.198MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 13.354MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 13.350MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 13.350MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 13.406MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 13.268MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 13.265MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 13.264MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 14.818MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 14.814MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 14.813MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 14.813MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 16.421MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 16.427MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 16.426MB for 2400016-byte allocation
I/dalvikvm-heap(13094): Grow heap (frag case) to 16.426MB for 2400016-byte allocation
//**-Not A log message: here i simply changed a variables name and restarted**
I/dalvikvm-heap(13497): Grow heap (frag case) to 12.995MB for 2400016-byte allocation
I/dalvikvm-heap(13497): Grow heap (frag case) to 13.002MB for 2400016-byte allocation
I/dalvikvm-heap(13497): Grow heap (frag case) to 13.002MB for 2400016-byte allocation
I/dalvikvm-heap(13497): Grow heap (frag case) to 13.002MB for 2400016-byte allocation

这就像关闭应用程序后保留的内存泄漏,在应用程序中我确实使用sharedPreferences来保存。但我没有看到这可以产生什么影响。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

Android应用程序不会简单地关闭,请参阅以下关于该主题的精彩博文: http://blog.radioactiveyak.com/2010/05/when-to-include-exit-button-in-android.html

堆增长是因为你的应用程序没有关闭,它只是隐藏了。实际上,你似乎确实有内存泄漏。更改变量名称时堆会缩小,因为生成了新的apk,手机上的应用程序被终止并重新安装了应用程序。