Android 中的垃圾收集器正在运行,但 ddms 中未显示任何内容已分配。分配跟踪器
在我的应用程序中,我小心地不要在主渲染循环中进行堆分配,以防止垃圾收集器执行其操作。
对我的应用程序进行一系列更改后,我突然看到垃圾收集器每隔一两秒就会被调用一次,并且每次调用都会释放大约 400k 的内存。
我回顾一下我所做的更改,并且渲染线程上没有发生任何显式分配。因此,我运行 ddms 并使用“分配跟踪器”工具,但除了与运行 ddms 相关的正常分配之外,没有发生任何分配。当然,对于 400k 字节显然没有显示足够的分配,这些字节显然每秒左右都会被垃圾回收
In my application, I'm careful not to make heap allocations in the main render loop, to prevent the garbage collector from having to do its thing.
After making a series of changes to my application, I suddenly see the garbage collector getting invoked every second or two, and it is freeing up around 400k of memory per invocation.
I look back at the changes that I made, and I don't have any explicit allocations happening on the render thread. So I run ddms and use the "Allocation Tracker" tool, but there are no allocations happening, other than the normal ones that are related to running ddms. And certainly not enough allocations shown for the 400k bytes that are apparently being garbage collected every second or so
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(我已经找到了解决方案,但为了其他人的利益而发布问题+答案)
事实证明,我能够跟踪问题以调用枚举类的 .values() 方法,该方法在每次通话。但由于某种原因,这些分配不会显示在 ddms 的分配跟踪器中,因此很难追踪。
幸运的是,我能够使用 git bisect 找到引入问题的具体更改,然后追踪到该更改中的确切问题。
编辑:
经过一些额外的测试后,克隆数组通常不会出现在分配跟踪器中。
附加信息:
当克隆对象时,这似乎是 Honeycomb 及以下版本中的一个问题。它将在 ICS 中修复。 (http://code.google.com/p/android/issues/detail?id=19831 )
(I had already found the solution but am posting the question+answer for other's benefit)
As it turns out, I was able to track the problem down to calling the .values() method of a enum class, which allocates a new array on every call. But for some reason, those allocations don't show up in ddms's allocation tracker, so it makes it rather difficult to track down.
Luckily, I was able to use git bisect to find the specific change that introduced the issue, and then tracked it down to the exact problem in that change.
Edit:
After some additional testing, it seems that cloning an array in general doesn't show up in the allocation tracker.
Additional Info:
This seems to be an issue in Honeycomb and below, when cloning an object. It will be fixed in ICS. (http://code.google.com/p/android/issues/detail?id=19831)
请提供有关垃圾收集器类型的信息。
位图分配,意味着实际的位图像素(不是非常小的位图信息)被分配到堆中,但对于 Android 版本低于 3.0 (Honeycomp) 的任何分配跟踪工具都不可见。所以如果你正在加载位图信息,GC外部分配将会被调用。
Please provide info about the kind of garbage colletor.
Bitmap allocation, meaning the actual bitmap pixels(not bitmap information which is very small) is allocated into the heap, BUT not visible to any allocation tracker tool for android version below 3.0 (Honeycomp). So if you are loading bitmap information GC extrernal allocation will be called.