在我的应用程序中,我注意不要在主渲染循环中进行堆分配,以防止垃圾收集器不得不做它的事情.
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.
对我的应用程序进行一系列更改后,我突然发现垃圾收集器每隔一两秒就会被调用一次,每次调用它会释放大约 400k 的内存.
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.
我回顾了我所做的更改,并没有在渲染线程上发生任何显式分配.所以我运行 ddms 并使用Allocation Tracker"工具,但除了与运行 ddms 相关的正常分配外,没有发生任何分配.对于显然每秒左右被垃圾收集的 400k 字节显示的分配肯定不够
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
(我已经找到了解决方案,但我发布问题+答案是为了他人的利益)
(I had already found the solution but am posting the question+answer for other's benefit)
事实证明,我能够将问题追溯到调用枚举类的 .values() 方法,该方法会在每次调用时分配一个新数组.但是由于某种原因,这些分配没有显示在 ddms 的分配跟踪器中,因此很难追踪.
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.
幸运的是,我能够使用 git bisect 找到导致问题的具体更改,然后追踪到该更改中的确切问题.
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.
经过一些额外的测试,似乎克隆数组一般不会出现在分配跟踪器中.
After some additional testing, it seems that cloning an array in general doesn't show up in the allocation tracker.
附加信息:克隆对象时,这似乎是 Honeycomb 及以下版本中的一个问题.它将在 ICS 中修复.(http://code.google.com/p/android/issues/detail?id=19831)
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 中的垃圾收集器正在运行,但 ddms 的分配跟踪器中没有显示任何已分配的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!