Is it possible for memory used by my program to remain after it has closed?

I've noticed when I open and close my program multiple times, my ram starts filling up. Up to gigs worth of ram. After restarting my computer and not opening it, I haven't had this problem.

What I'm confused about is that I thought Windows cleared up all the memory used by an application after it closes. How true is that?

Then again, for all I know, it might have nothing to do with my program.
Maybe it was something else and I'm just pointing fingers at something completely unrelated. I just want to know if it's safe to start running it again.

This is probably more closely related to Visual Studio or Operating Systems, but I didn't know of any forum for that.
Last edited on
Do you have memory leaks in your program? Does this also happen with simple hello world programs?

Maybe the memory is being kept alive by your IDE - does it go away when you close your IDE?
I don't know if I have memory leaks in my program but it's likely since I don't know much about what to delete or how to delete stuff at the end of a program.

It doesn't go away after I close Visual Studio either.

Like I said, it could have nothing to do with the program and might just be some unrelated program on my computer. I just want to know if memory created by a program can be left behind when a program closes.
Last edited on
It shouldn't happen in a modern OS, but Windows isn't exactly known for being bugproof.

If you want to avoid memory leaks in your program, you shouldn't use new. That's not a joke.
http://www.LB-Stuff.com/pointers
That clears things up a lot. Thanks.

There aren't any news in my program, so I'm guessing it's something else taking up all the memory.
Can you create a minimal test case? Try removing code until you have the minimal amount to reproduce the issue. If at some point the issue goes away, then the code you removed is the culprit.
> I've noticed when I open and close my program multiple times, my ram starts filling up.

Your ram should start filling up if your program is performing large amounts of file i/o on different files or using a lot of memory mapped sections. In this scenario, you ought to be worried only if the ram does not start filling up when the program has been run.

One of the strengths of Windows, right from NT 3.51, is excellence in memory management. So much so, that many of Dave Cutler's innovations are now incorporated into other operating systems like the BSDs and Linux.


> There aren't any news in my program, so I'm guessing it's something else taking up all the memory.

Memory leaks in the program are irrelevant; all private memory of a process is released when the process ends. (Antivirus software may be mapping some of the process memory; but this does not stay for long after the process has ended.)


For more information:
http://blogs.technet.com/b/askperf/archive/2010/08/13/introduction-to-the-new-sysinternals-tool-rammap.aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/aa364218(v=vs.85).aspx
Last edited on
Visual Studio certainly consumes a lot of memory, especially in debug mode. So it's probably not much to worry about.
Topic archived. No new replies allowed.