Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

When is mono releasing a gref of an activity?

MatthiasMatthias DEMember ✭✭


during profiling my app a bit I have discovered that mono keeps ALL my ever opened activities alive and so all gref's.
On the emulator I can easily run into a crash because my gref's are depleted and the count is not fully in sync between dalvik and mono so the full gc comes way to late.

Even in a very simple scenario with 3 activities (A, B, C) each with a button on it and a simple handler. When I navigate A -> B -> C and back to A with the backkey it seems that B and C are never fully finalized. When I repeat that navigation 10 times the profiler shows 10x Activity B and C with gc root pointing to the native stack. Together with these references my gref count is constantly increasing and never goes down except I do a manual GC.Collect() (the profiler drops to 0 activities as well).

Is that really the expected behavior?
As workaround I'm calling GC.Collect() in the OnDestroy but that is still very expensive and not really desired. Is there any other way or do I really have to rely on the automatic full collect at 90% gref usage (comes to late on emulator for me)?


  • Hello, could you solve this ? I have the same problem and my application get OutOfMemoryException after a time to use

Sign In or Register to comment.