Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
304 views
in Technique[技术] by (71.8m points)

enums - Garbage collector in Android is running, but nothing is shown as being allocated in ddms' allocation tracker

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

(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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...