Android error: HeapWorker is wedged... BinderInternal$GcWatcher
M开发者_运维问答y Android app is crashing with the following error:
ERROR/dalvikvm(7051): HeapWorker is wedged: 10037ms spent inside Lcom/android/internal/os/BinderInternal$GcWatcher;.finalize()V
So it looks like the GCWatcher
is taking > 10s to finalize.
This happens while an AsyncTask is retrieving/passing data from a remote server via http. It doesn't always throw this error and it's only recently started happening... previously this has been working fine and the app code is unchanged.
Anyone know what's causing this error and how I can stop it?
The GcWatcher stuff is a bit of a hack. The problem it's trying to solve is that resources in one process can prevent the release of resources in another process, and the resources are only released by the VM's garbage collector. The system wants to periodically force garbage collection to keep things from building up in quiet processes that rarely GC, so it tries to keep track of when the last GC happened by creating a finalizable object and recording when the finalizer runs.
The GcWatcher.finalize method is pretty trivial. If it's taking 10 seconds to run, it's because the thread is being starved out by the rest of the system. What usually happens is some other low-priority thread in that process is trying to do an allocation, but ends up stalled because the CPU doesn't want to give it any more time. The (normal-priority) HeapWorker thread gets stuck when GcWatcher.finalize tries to create a new finalizable object. (cf. "priority inversion")
On a quiet system this shouldn't happen, because every thread should have enough time to get some work done.
You should have a full stack trace in logcat. Look at where the other threads are. You may also want to run a program like "top" to see if something you installed recently is soaking up all the CPU and exacerbating the situation.
What version of Android are you running? The thread priority stuff has changed with each release (most recently using the "cgroup" mechanism).
精彩评论