我遇到了一个让我疯狂的问题。我在我的代码中使用了Google Map API V2,当我移动地图时,我可以看到以下Logcat输出(在Nexus 7上):
01-23 21:17:10.724: D/dalvikvm(5484): GC_FOR_ALLOC freed 4531K, 21% free 12911K/16312K, paused 29ms, total 29ms
01-23 21:17:10.724: I/dalvikvm-heap(5484): Grow heap (frag case) to 13.043MB for 285724-byte allocation
01-23 21:17:10.744: D/dalvikvm(5484): GC_FOR_ALLOC freed 200K, 22% free 12990K/16592K, paused 25ms, total 25ms
01-23 21:17:12.074: D/dalvikvm(5484): GC_FOR_ALLOC freed 1326K, 23% free 12893K/16592K, paused 30ms, total 31ms
01-23 21:18:04.854: D/dalvikvm(5484): Debugger has detached; object registry had 1 entries
01-23 21:18:07.374: D/dalvikvm(5484): GC_FOR_ALLOC freed 658K, 23% free 12904K/16592K, paused 27ms, total 27ms
01-23 21:18:07.384: I/dalvikvm-heap(5484): Grow heap (frag case) to 13.763MB for 1048592-byte allocation
01-23 21:18:07.404: D/dalvikvm(5484): GC_FOR_ALLOC freed 2K, 21% free 13925K/17620K, paused 27ms, total 27ms
01-23 21:18:07.714: D/dalvikvm(5484): GC_FOR_ALLOC freed 2127K, 26% free 13054K/17620K, paused 29ms, total 29ms
01-23 21:18:44.694: D/dalvikvm(5484): GC_CONCURRENT freed 1894K, 27% free 12970K/17620K, paused 4ms+5ms, total 56ms
01-23 21:18:46.684: D/dalvikvm(5484): GC_CONCURRENT freed 1738K, 27% free 12996K/17620K, paused 4ms+2ms, total 53ms
01-23 21:18:49.254: D/dalvikvm(5484): GC_CONCURRENT freed 1756K, 27% free 13014K/17620K, paused 2ms+8ms, total 77ms
01-23 21:18:56.864: I/dalvikvm(5484): Jit: resizing JitTable from 8192 to 16384
01-23 21:18:56.934: D/dalvikvm(5484): GC_CONCURRENT freed 1840K, 21% free 13010K/16312K, paused 2ms+4ms, total 49ms
01-23 21:18:59.434: D/dalvikvm(5484): GC_CONCURRENT freed 1779K, 21% free 12995K/16312K, paused 4ms+5ms, total 50ms
01-23 21:19:03.414: D/dalvikvm(5484): GC_CONCURRENT freed 1781K, 21% free 13007K/16312K, paused 2ms+3ms, total 48ms
堆不断增长和增长,我不知道我能做些什么。我通过网络搜索并通过stackoverflow搜索,但对我来说没有任何有用的答案。 我希望有人能找到错误。我是Android新手,所以请欣赏。
EDIT1:堆转储:
EDIT2:MAT分析
怀疑1:
One instance of "maps.by.a" loaded by "dalvik.system.PathClassLoader @ 0x4480cfa8" occupies 1.002.352 (22,33%) bytes. The memory is accumulated in one instance of "maps.by.d" loaded by "dalvik.system.PathClassLoader @ 0x4480cfa8".
Keywords
maps.by.a
dalvik.system.PathClassLoader @ 0x4480cfa8
maps.by.d
怀疑2:
3.507 instances of "java.lang.Class", loaded by "<system class loader>" occupy 795.104 (17,72%) bytes.
Biggest instances:
•class com.ibm.icu4jni.util.Resources$DefaultTimeZones @ 0x401fccc8 - 151.744 (3,38%) bytes.
•class android.text.Html$HtmlParser @ 0x4016d288 - 126.592 (2,82%) bytes.
•class org.apache.harmony.security.fortress.Services @ 0x40091188 - 51.456 (1,15%) bytes.
Keywords
java.lang.Class
怀疑3:
8.168 instances of "java.lang.String", loaded by "<system class loader>" occupy 529.048 (11,79%) bytes.
Keywords
java.lang.String
答案 0 :(得分:3)
首先,你的堆不会“继续增长”。它在12893K和13054K之间徘徊,上升和下降,其中一个异常峰值在13925K。就个人而言,我在日志中看不到任何让我担心的事情。
关于你的MAT输出,如果这三个是罪魁祸首,那么没有一个是令人惊讶的。后两者说“我正在为Android编写应用程序”,因为这些应用程序始终存在于任何Android应用程序中。第一个表明Maps V2有一个相当胖的对象。同样,我在输出中看不到任何暗示问题的内容。