samedi 25 avril 2015

How can I tell how much memory my application is using in C#?


If I want to see how much memory my java application uses, I can write

 class Test{
  public static void main (String[] args) {
    Runtime rt = Runtime.getRuntime();
    System.out.println(rt.totalMemory() - rt.freeMemory());
  }
}

How can I do the same for C#? This:

using System;
using System.Diagnostics;

public class Test
{
    public static void Main()
    {
        Process proc = Process.GetCurrentProcess();
        Console.WriteLine(proc.PrivateMemorySize64);
    }
}

as explained in this post During execution, how can a java program tell how much memory it is using? seems to only print the total number of bytes allocated for the application, same as "Runtime.getRuntime().totalMemory()" would do.


Aucun commentaire:

Enregistrer un commentaire