Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 3858 [details]
I’m having a problem with my app that causes it to go crazy and consume tons of CPU, even after it’s closed.
I’ve isolated this down to a sample repro app, which I have attached. The problem happens if I try to remove an instance of AndroidGameView from the tree.
The attached code is simply the OpenGL starter package with the addition of a button that allows you to add and remove the AndroidGameView from view. Here’s what you’ll see when you run the attached code: (I ran it in Xamarin.Android 4.6.00049)
1. When the app starts up, tap the button to add the AndroidGameView.
2. When I look at logcat while it runs, I see a GC running about once every 3-5 seconds, and by running “adb shell top -m 10 -d 1” I can see the CPU of the app ranging from 4-15%. This is all normal and expected.
3. Now tap the button again to remove the AndroidGameView from view.
4. Now, logcat shows the GC running multiple times per second, and the CPU of the app is 25-40%. This is not normal, as the app is idle at this point. It continues eating these resources forever, in some sort of infinite loop. The app still works and responds, but the resources are being eaten even though the app is idle.
5. Now, press the device’s home button. Notice the resources continue to be eaten even when the app is not active. Nothing short of a force-stop will free the CPU resources.
Obviously, this is a bug problem, and is already annoying my beta testers. I can’t release my app having it use up so much of the CPU for no reason, especially considering it persists even after the app is closed.
Is there any workaround for this?
Thanks to Dean Ellis for providing a work-around -- if you call Pause() *before* removing the AndroidGameView from the view tree, it seems to not go crazy anymore. However, the bug should still be fixed, since this still creates memory leaks (as outlined by bug 11922)
I found the issue and its been fixed in our codebase. Not sure when the next release is yet but it should make it into that.
This commit got into the 4.6.7 release, but I'm trying to verify and I'm seeing similar behavior to the original description, with slightly different average CPU usages.
Starting the app and adding the initial AndroidGameView gives me about an average of 18% CPU usage.
Once I remove the AndroidGameView, the app is eating about 80% of my CPU.
When I press the home button, the CPU usage fluctuates between 35% and 80%, but never dips lower than that 35% mark.
The workaround still works for me, adding a _gl.Pause() call before the view removal makes the CPU sit idle when expected.
Gonna have to REOPEN this one.
Galaxy Nexus w/ 4.2.2
Created attachment 4006 [details]
Full app test case
Here is the sample showing the issue.
Run `adb shell top -m 10 -d 1` to verify the CPU usage at different execution points.
The call to stop/Pause is needed when you remove it from the layout. The reason is you need to stop the render thread when you are not using the AndroidGameView. The fix was to make sure the render thread actually exited, which it didn't before and caused the view to never be disposed.
Ah ok, so the original issue here was INVALID.