Shouldn't all memory be freed after a page load?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • myNameIsChris
    New Member
    • Feb 2010
    • 3

    Shouldn't all memory be freed after a page load?

    Sporadically, I am receiving "out of memory" errors on my websites. In my performance monitor (Debug Diagnostic Tool), I can watch virtual bytes skyrocket until it causes an "out of memory" error on my website.

    What could be causing this? Even if I have piss-poor code with plenty of unclosed, un-nothing'ed objects, shouldn't the memory be freed after the page is served to the user? That is, nothing should be persisted from one page visit to another page visit. I am using no session variables.

    Forgive me if this belongs in a forum about servers. Perhaps I'll try my luck there as well.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    That's a good question, and the answer depends on if your question starts with "should" or "will". Should all the memory be freed? yes. Will it? no.

    You still need to close your objects just to be on the safe side.

    Jared

    Comment

    • myNameIsChris
      New Member
      • Feb 2010
      • 3

      #3
      Thanks for the reply.

      I'm a little uneasy about your "be on the safe side" comment. I'm aware that closing all objects (and writing more efficient code overall) wouldn't HURT the memory usage, in fact it would help.

      But I want to know if and why memory is persisted from one page load to another (and seemingly kept on some sort of memory stack, according to IIS debug diagnostic tool's report of virtual/private bytes used).

      Broadly, here is how I would imagine a server works:
      -Incoming request for a page "index.asp"
      -Ok, "index.asp" will require 50mb of memory usage. Server serves the page, disconnects with the requestor for "index.asp" and can then completely forget about that page request. free all memory. act like it never happened.

      kind of like how you can open up a program (it will be using RAM), and then you can close the program and free the RAM.

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        But your program (IIS) never shuts down and it is IIS that creates the server objects, not the script that is calling them. Does that make sense? As far as I know it is the server objects that you need to worry about leaking, so every time you say server.createob ject you will need to destroy it.

        I'm far from a computer science theoretician, so I could be way wrong. I once told someone, "no, everything will close down by itself" and I got called on it. I personally have written my share of bad, sloppy, and unclosed code, and it rarely comes back to haunt me, I'm just trying to tell you how I understand things.

        Jared

        Comment

        Working...