Forum General

Programmatically determine memory used by app?

JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
edited December 2017 in General

To help monitor/track down memory leaks, we need to know what memory our app is consuming.

This is for a Xamarin.Forms app; currently we're only running on Android, but will be on iOS in the future.

I know we can get the OS memory used on the device, in the Droid project, by using code like below:

public static MemoryInfo GetMemoryInfo()
        MemoryInfo retVal = new MemoryInfo();
        retVal.MaxMemory = Java.Lang.Runtime.GetRuntime().MaxMemory();
        retVal.FreeMemory = Java.Lang.Runtime.GetRuntime().FreeMemory();
        retVal.TotalMemory = Java.Lang.Runtime.GetRuntime().TotalMemory();

        return retVal;

Is there any mechanism for getting a figure for the memory being consumed in the Mono runtime?

Best Answer


  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭✭
    Accepted Answer

    As answered on StackOverflow, the solution should be to use GC.GetTotalMemory

  • batmacibatmaci DEMember ✭✭✭✭✭

    I feel ignorant. what does it mean exactly "consumed in the Mono runtime?"? Is it unmanaged memory?

Sign In or Register to comment.