Android 中的垃圾收集器正在运行,但 ddms 中未显示任何内容已分配。分配跟踪器

发布于 2024-12-02 17:29:05 字数 256 浏览 1 评论 0原文

在我的应用程序中,我小心地不要在主渲染循环中进行堆分配,以防止垃圾收集器执行其操作。

对我的应用程序进行一系列更改后,我突然看到垃圾收集器每隔一两秒就会被调用一次,并且每次调用都会释放大约 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

当梦初醒 2024-12-09 17:29:05

(我已经找到了解决方案,但为了其他人的利益而发布问题+答案)

事实证明,我能够跟踪问题以调用枚举类的 .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)

无敌元气妹 2024-12-09 17:29:05

请提供有关垃圾收集器类型的信息。
位图分配,意味着实际的位图像素(不是非常小的位图信息)被分配到堆中,对于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文