17

当我在模拟器上运行我的应用程序时,Logcat 显示:

04-22 16:21:30.685: D/dalvikvm(967): GC_CONCURRENT freed 1545K, 20% free 7019K/8720K, paused 78ms+17ms, total 360ms

04-22 16:21:30.685: D/dalvikvm(967): WAIT_FOR_CONCURRENT_GC blocked 143ms
04-22 16:21:31.845: D/dalvikvm(967): GC_CONCURRENT freed 1552K, 20% free 7019K/8720K, paused 116ms+18ms, total 554ms

04-22 16:21:31.845: D/dalvikvm(967): WAIT_FOR_CONCURRENT_GC blocked 268ms
04-22 16:21:32.435: D/dalvikvm(967): GC_CONCURRENT freed 1545K, 20% free 7019K/8720K, paused 75ms+9ms, total 192ms

04-22 16:21:32.435: D/dalvikvm(967): WAIT_FOR_CONCURRENT_GC blocked 73ms
04-22 16:21:32.945: D/dalvikvm(967): GC_CONCURRENT freed 1552K, 20% free 7019K/8720K, paused 75ms+10ms, total 209ms

04-22 16:21:32.945: D/dalvikvm(967): WAIT_FOR_CONCURRENT_GC blocked 70ms
04-22 16:21:33.434: D/dalvikvm(967): GC_CONCURRENT freed 1545K, 20% free 7019K/8720K, paused 78ms+12ms, total 192ms

这一直持续到我退出应用程序。有什么建议吗?谢谢

4

5 回答 5

8

似乎您正在创建许多新对象并很快将它们丢弃。

对于 WAIT_FOR_CONCURRENT_GC 看这个: WAIT_FOR_CONCURRENT_GC 阻塞是什么意思?

这意味着您尝试分配内存(例如对象创建)并且它不适合内存。这就是释放 GC_CONCURRENT 的原因。它只是通常的垃圾收集。

如果您遇到性能问题,请尝试重用对象或保留它们。

于 2013-04-22T16:40:22.910 回答
5

这意味着您正在执行太多操作并且正在使用大量内存。因此,正在调用 GC(垃圾收集器)来释放内存。

04-22 16:21:30.685: D/dalvikvm(967): GC_CONCURRENT freed 1545K, 20% free 7019K/8720K, paused 78ms+17ms,总共360ms

freed 表示释放了多少内存

GC_CONCURRENT 当堆太大而无法防止溢出时调用。

paused 78ms+17ms – 表示 GC 完成收集所用的时间。

参考

另外进行内存转储并使用 MAT 工具分析转储。

于 2013-04-22T16:35:56.970 回答
2

有时它发生在你有一个永无止境的循环只是因为某些条件总是正确的。

尝试首先弄清楚它是否是这种情况,因为它主要是因为这个而发生的。

于 2013-08-16T15:07:34.390 回答
2

Agree mostly with @luxer, but I believe it's not that you are allocating too many objects, but you are allocating some huge objects. If you refer to the link pointed by @luxer about WAIT_FOR_CONCURRENT_GC, you will realize that a second gc is being triggered in your app while a concurrent gc (which is typically triggered when the heap occupancy hits a soft limit) is in progress. The second gc could have been triggered by you explicitly or because an allocation failed. Since you have not indicated that you're calling System.gc(), I would assume that your allocations are failing and the system is trying to do a gc.

So, yeah, you should seriously consider reusing some huge objects instead of allocating them each time. This is a better practice, but if for some reason you're unable to do that, you can probably bump your heap size (by setting large heap) and that may help.

于 2013-06-08T23:53:26.907 回答
0

我能够通过调试我的代码来解决我的问题:有一个 DB 操作潜伏在一个无限的 while 循环中,它正在填充 bean 并因此导致内存泄漏。

也许如果您像我一样是新手,请检查 while/do-while/for 循环和循环中完成的对象分配。未关闭的连接和游标也应该关闭。

谢谢,

于 2019-05-14T05:24:49.113 回答