Trigger Garbage Collection from Xamarin Profiler

CosminStirbuCosminStirbu ROMember ✭✭

Hi,

Is it possible to trigger the Garbage Collector from Xamarin Profiler when using Allocations?
Triggering the Garbage Collector before taking a snapshot makes it easy to understand if you truly have leaks or not.

Thank you,
Cosmin

Answers

  • RodrigoMoyaRodrigoMoya ESXamarin Team Xamurai

    When you trigger a snapshot, most times (*) the runtime will do a GC. So, after a snapshot every object that is alive is either alive because some other object is referencing it, or it is a leak.

    • not always on Android platforms though
  • CosminStirbuCosminStirbu ROMember ✭✭

    Thanks for your answer.

    By by most of time do you mean that at least on the .NET Runtime side the GC is triggered, but on the JVM side it isn't always triggered?

    So then would it be fair to state the following?

    • On iOS after triggering a Snapshot from Xamarin Profiler, any object that is alive, and we know there shouldn't be any references to it, is a leak
    • On Android after triggering a GC from Android Studio and triggering a Snapshot from Xamarin Profiler, any object that is alive, and we know there shouldn't be any references to it, is a leak (not sure if you can have both Android Studio and Xamarin Profiler "connected" to the same device at the same time - but we'll look into it and come back with our findings as well)

    Any plans of forcing the GC to always run when triggering a Snapshot on all platforms in the future?

    Thank you,
    Cosmin

  • CosminStirbuCosminStirbu ROMember ✭✭

    So it seems that my assumption was wrong.

    You cannot "connect" both Android Studio and Xamarin Profiler at the same time - Xamarin Profiler crashes when you also connect Android Studio.

    Can we force GC on both JVM and Mono side when capturing a snapshot?

  • RodrigoMoyaRodrigoMoya ESXamarin Team Xamurai

    @CosminStirbu said:
    Thanks for your answer.

    By by most of time do you mean that at least on the .NET Runtime side the GC is triggered, but on the JVM side it isn't always triggered?

    So then would it be fair to state the following?

    • On iOS after triggering a Snapshot from Xamarin Profiler, any object that is alive, and we know there shouldn't be any references to it, is a leak

    Well, if an object is alive after a snapshot/GC, it is because something is keeping a reference to it. It is a leak if there shouldn't be a reference to it, so for checking that, use the Paths to roots feature in the profiler, which will show you what is keeping that object alive.

    • On Android after triggering a GC from Android Studio and triggering a Snapshot from Xamarin Profiler, any object that is alive, and we know there shouldn't be any references to it, is a leak (not sure if you can have both Android Studio and Xamarin Profiler "connected" to the same device at the same time - but we'll look into it and come back with our findings as well)

    Same answer :)

    Any plans of forcing the GC to always run when triggering a Snapshot on all platforms in the future?

    they behave differently because of platform differences, so nothing we can do about it AFAIK. Although, as I said, in most cases, triggering a snapshot in Xamarin Profiler for an Android app would most of the times force a GC.

  • RodrigoMoyaRodrigoMoya ESXamarin Team Xamurai

    Ah and no, I don't think you can connect 2 profilers to the same app at the same time. But, could you please share the Profiler.log for the case when it crashes when you connect Android Studio to the app?

  • CosminStirbuCosminStirbu ROMember ✭✭

    I've attached both the .log and the crash reported by Apple.

    The log doesn't really provide much useful information though.

Sign In or Register to comment.