We are developing an application that inputs data in a conversational format.
For this reason, a very large number of screen transitions are required.
One cycle is to register data at the end of the screen from screen 1 to screen 5
This will last forever until the user exits
However, when you actually run it, it will fall after freezing if you switch screens 750 times, regardless of the amount of data included in Activity.
How can I repeat data entry endlessly?

Error message

No error message is displayed.

Applicable source code
public class Gamen1Activity: Activity
    private Button _button;
    protected override void OnCreate (Bundle savedInstanceState)
        base.OnCreate (savedInstanceState);
        SetContentView (Resource.Layout.Main);
        _button = FindViewById<Button>(Resource.Id.SystemStartButton);
        _button.Text = "Button";
        _button.Click + = (s, e) =>{
            var nextType = typeof (Gamen2Activity);// specify next Activity here
            var nextIntent = new Intent (this, nextType)
            StartActivity (nextIntent);

After the screen transition with StartActivity, Finish method was executed in the called Activity.

Supplemental information (FW/tool version etc.)

In the output window, it was confirmed that there was an increase in memory during execution, but it did not seem to be completely released in Finish.
The development of Xamarin and Andoroid was the first time, and while investigating the information on the net, I investigated what kind of method is good for processing the above requirements, but I could not get clear information.

  • Answer # 1

    I don't know what kind of app, but "I can withstand more than 750 screen transitions (forever and endlessly)" seems to be an over-requirement. If it becomes.

    The first is to stop using Xamarin.Android to simplify the problem and try a similar reproduction in Android Studio (Java or Kotlin).

    Xamarin.Android does not only manage the memory of the Java world, but also manages the memory of the .NET world in parallel, so it is difficult to isolate which problem is occurring.

    Java interoperability mechanism and Java binding project in Xamarin.Android-Build Insider

    Next, if you can reproduce the problem in Android Studio (Java or Kotlin), you can find out where the memory leak occurred. A library called LeakCanary is useful for this.


    There may be other similar libraries.

    Also, it ’s basically


    Finish didn't seem to be fully open

    Activity's memory management is entrusted to the Android OS, so it is usually not freed as soon as you finish.
    Also, since it is Java (JVM), the memory will not be released if garbage collection is not executed. Garbage collection can be enforced withjava.lang.System.gc ().

    About Activity Lifecycle | Android Developers

    So in the code above, instances of in-class variables such as_buttonwill remain unless Activity is destroyed by the system and garbage collected.

    Nevertheless, don't worry too much because the system should detect that the memory is getting low and discard the Activity accordingly.

    In addition, I think that Activity will be destroyed more positively if it is set to "Do not keep activity" in the setting for developers.

    Finally, this is subjective, but the mobile OS is more important than "continuing to work forever" rather than "being able to recover from the continuation even if the terminal suddenly ends" Depending on the device (or the original Android OS itself), I think that it is not strange that there is a problem related to long-term operation.