none
Programaticaly detecting low memory state. RRS feed

  • Question

  • I have an application (test infrastructure) that needs to change its behavior when available memory is getting low.
    Once upon a time I would have subscribed to SystemEvents.LowMemory event.

    Now that the LowMemory event has been deprecated, how should I check for low memory?


    Thanks
    Monday, February 16, 2009 7:26 PM

Answers

  • SystemEvents.LowMemory was in no way representative for the likelihood to get OOM.  You'll get that when you run low on virtual memory space.  As such, GC.GetTotalMemory(false) should be a reasonably decent measure, assuming your program doesn't allocate a lot of unmanaged memory and doesn't allocate large chunks that wouldn't fit when the address space gets fragmented.  No guarantees though, be sure to leave lots of elbow room.
    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Monday, February 23, 2009 6:57 AM
    Monday, February 16, 2009 8:46 PM
    Moderator