Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Detecting low memory

Detecting low memory

Scheduled Pinned Locked Moved C#
jsonperformancequestion
8 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Madmaximus
    wrote on last edited by
    #1

    Hi all, I am trying to have my program detect when the system's memory is low. Is there an event or a windows API that I can use to achieve this? Thanks in advance.

    L realJSOPR T P P 5 Replies Last reply
    0
    • M Madmaximus

      Hi all, I am trying to have my program detect when the system's memory is low. Is there an event or a windows API that I can use to achieve this? Thanks in advance.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      What for? No, I don't think you can do that in a reliable way, short of actually requesting lots of memory until you aren't getting any more. Each new version of Windows is trying harder to have all memory in use all the time, by caching everything they encounter. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      M 1 Reply Last reply
      0
      • M Madmaximus

        Hi all, I am trying to have my program detect when the system's memory is low. Is there an event or a windows API that I can use to achieve this? Thanks in advance.

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        It's called try/catch. That's the best you can do. Besides, what *is* low memory in windows? It pages to disk, so you shouldn't have to worry about it.

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        1 Reply Last reply
        0
        • M Madmaximus

          Hi all, I am trying to have my program detect when the system's memory is low. Is there an event or a windows API that I can use to achieve this? Thanks in advance.

          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          Get memory size usage using WMI and .NET 2.0 [^]

          1 Reply Last reply
          0
          • L Luc Pattyn

            What for? No, I don't think you can do that in a reliable way, short of actually requesting lots of memory until you aren't getting any more. Each new version of Windows is trying harder to have all memory in use all the time, by caching everything they encounter. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            M Offline
            M Offline
            Madmaximus
            wrote on last edited by
            #5

            I just need to find a way that will let me know if the OS's memory/resources is low. Is there a windows API or maybe an event in .Net that I can just plug-in to?

            T 1 Reply Last reply
            0
            • M Madmaximus

              I just need to find a way that will let me know if the OS's memory/resources is low. Is there a windows API or maybe an event in .Net that I can just plug-in to?

              T Offline
              T Offline
              The Man from U N C L E
              wrote on last edited by
              #6

              I haven't had it happen since I got more than 512MB ram, and set a decent size page file, however I recall windows pops a message for you if you are running out of memory. It would ask permission to increase the size of the page file. Leave it to Windows I say.

              If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

              1 Reply Last reply
              0
              • M Madmaximus

                Hi all, I am trying to have my program detect when the system's memory is low. Is there an event or a windows API that I can use to achieve this? Thanks in advance.

                P Offline
                P Offline
                Paul Michalik
                wrote on last edited by
                #7

                Yes, you can observe the GC.GetTotalMemory, query the WMI information or use the unmanaged APIs. But as you've been told above, this does not make much sense in general... Your question makes sense, if your application itself manages chunks of memory for specific purposes, such as caching. P.S. The situation is different, if we are talking about some kind of mobile device...

                modified on Sunday, August 29, 2010 6:54 AM

                1 Reply Last reply
                0
                • M Madmaximus

                  Hi all, I am trying to have my program detect when the system's memory is low. Is there an event or a windows API that I can use to achieve this? Thanks in advance.

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #8

                  It's generally pointless to try.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups