14

Is there a way to know the current used memory in the current process?

I checked many questions: How to get the amount of memory used by an application

How to get memory available or used in C#

They are not available in .Net Standard 1.6.

Saw
  • 6,199
  • 11
  • 53
  • 104

1 Answers1

11

Here you can check how it is done in HealthChecks project. You can use Process class from System.Diagnostics namespace.

* EDIT *

System.Diagnostics.Process Nuget package might need to be added.

Only xxxx64 memory properties are supported in .NET Standard (for example PrivateMemorySize64 and not PrivateMemorySize).

Saw
  • 6,199
  • 11
  • 53
  • 104
Krzysztof Branicki
  • 7,417
  • 3
  • 38
  • 41
  • 3
    It works like a charm, thanks, it turned out that only the XXXXX64 (for example PrivateMemorySize64) properties are supported in .NET Standard (for example proc.PrivateMemorySize64) – Saw Jul 23 '17 at 22:33
  • 1
    .NET Core 2.1, added System.Diagnostics.Process NuGet package, but all "64" properties return 0 under Ubuntu (WSL). – Martin Plante Nov 22 '18 at 15:06
  • I encountered the same problem for ubuntu (I am running in docker skd-runtime 2.2 ). – Eitan Mar 18 '19 at 10:44