减少内存警告并改善内存管理

时间:2014-02-17 16:46:59

标签: java android memory

我正在做一个从服务中获取数据并在图表中表示的应用程序。 App运行正常,但在logcat中出现了很多GC_FOR_ALLOC消息。

无论如何都要减少这些消息?任何功能还是什么?

这是logcat:

02-17 17:40:37.427: D/dalvikvm(30112): GC_FOR_ALLOC freed 275K, 2% free 16994K/17300K, paused 10ms, total 10ms
02-17 17:40:39.397: D/dalvikvm(30112): GC_FOR_ALLOC freed 516K, 4% free 16993K/17540K, paused 8ms, total 8ms
02-17 17:40:39.987: D/dalvikvm(30112): GC_FOR_ALLOC freed 512K, 4% free 16993K/17540K, paused 10ms, total 10ms
02-17 17:40:40.287: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16993K/17540K, paused 9ms, total 9ms
02-17 17:40:40.577: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16994K/17540K, paused 8ms, total 8ms
02-17 17:40:41.117: D/dalvikvm(30112): GC_FOR_ALLOC freed 512K, 4% free 16993K/17540K, paused 8ms, total 8ms
02-17 17:40:42.687: D/dalvikvm(30112): GC_FOR_ALLOC freed 512K, 4% free 16993K/17540K, paused 9ms, total 9ms
02-17 17:40:45.887: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16993K/17540K, paused 9ms, total 9ms
02-17 17:40:47.187: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16993K/17540K, paused 9ms, total 10ms
02-17 17:40:47.457: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16993K/17540K, paused 8ms, total 8ms
02-17 17:40:47.737: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16994K/17540K, paused 10ms, total 10ms
02-17 17:40:48.817: D/dalvikvm(30112): GC_FOR_ALLOC freed 512K, 4% free 16994K/17540K, paused 8ms, total 8ms
02-17 17:40:49.097: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16994K/17540K, paused 8ms, total 8ms
02-17 17:40:49.417: D/dalvikvm(30112): GC_FOR_ALLOC freed 512K, 4% free 16994K/17540K, paused 15ms, total 15ms
02-17 17:40:49.687: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16994K/17540K, paused 10ms, total 10ms
02-17 17:40:49.967: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16994K/17540K, paused 9ms, total 9ms
02-17 17:40:50.237: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16994K/17540K, paused 9ms, total 9ms
02-17 17:40:50.507: D/dalvikvm(30112): GC_FOR_ALLOC freed 512K, 4% free 16993K/17540K, paused 8ms, total 8ms
02-17 17:40:50.777: D/dalvikvm(30112): GC_FOR_ALLOC freed 511K, 4% free 16994K/17540K, paused 8ms, total 8ms
02-17 17:40:51.257: D/dalvikvm(772): GC_FOR_ALLOC freed 972K, 44% free 31389K/55540K, paused 69ms, total 69ms

感谢

1 个答案:

答案 0 :(得分:0)

GC_FOR_ALLOC只是意味着没有足够的内存来完成分配任务,因此需要通过GC分配更多的空间。

当Android启动时,它从一个小堆开始,随着应用程序的增长和消耗内存而增长。在增加内存之前,运行GC_FOR_ALLOC,这是标准的预期行为。这不一定是因为你的应用程序占用了太多内存。

从您的logcat输出中,似乎没有任何奇怪的事情发生。如果要关闭这些消息,它们的日志级别为DEBUG。任何日志级别都高于此值,您将看不到它们。