0

Is their is an Equivalent of Runtime class (of java) in c# Actually I am trying to convert these operation to c#

Runtime runtime = Runtime.getRuntime(); return runtime.totalMemory() - runtime.freeMemory();

Anurag Sharma
  • 4,839
  • 13
  • 59
  • 101

1 Answers1

2

If you're just trying to get at the current memory usage, you want the GC class.

For example:

long memory = GC.GetTotalMemory(true); // Allow a brief time for GC/finalization

The GC class is also where you can find members to suggest garbage collection, wait for pending finalizers, and the like.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks Jon for the answer, But I wonder whats the equivalent of runtime.freeMemory(); in C# – Anurag Sharma Apr 29 '12 at 20:47
  • EDIT: nevermind, misunderstood. This help? http://stackoverflow.com/questions/750574/how-to-get-memory-available-or-used-in-c-sharp – Chris Sinclair Apr 29 '12 at 20:53
  • @AnuragSharma: You don't need to do that in .NET, as `GetTotalMemory` only returns memory known to be allocated to objects - it doesn't include the "allocated but currently unused" memory. – Jon Skeet Apr 29 '12 at 21:09