0

嗨,我已经阅读了与 android 中的增长堆有关的错误

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 来保存东西。但我看不出这如何在这里产生影响。有任何想法吗?

4

1 回答 1

1

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

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

于 2012-08-14T09:02:30.943 回答