在Android的垃圾收集器在运行,但没有显示为被分配在DDMS“分配跟踪分配、垃圾、收集器、Android

2023-09-05 00:33:27 作者:只求你不要拒绝

在我的应用程序,我小心不要不得不做的事情做堆分配在主渲染循环,以prevent垃圾收集器。

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,并使用分配跟踪工具,但没有分配发生,比常年偏多与相关的运行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平分找到介绍这个问题的具体变化,然后跟踪它的确切问题,即改变。

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.

附加信息: 此克隆对象时似乎是在蜂窝及以下,是一个问题。这将是固定在ICS。 (http://$c$c.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)