Reputation: 113
I'm using C++/CLI and .Net 4.0 (managed c++), my IDE is visual studio 2012 RC.
My program is almost entirely written in C++/CLI (I only have a five lines native code) and I'm wondering how effective garbage collection is and if it's really working for me.
When I start my program (I'm using some forms) it takes about 3-5 MB RAM. But after the program has been running for a while (the same code is running over and over again with new information entered to it) it uses more and more memory (after 5-15 minutes it takes about 10-25 MB RAM) and the amount of RAM only increases?
Why is this? And isn't this exactly what garbage collection should prevent?!
And would it be bad to force garbage collection every minute or so?
Upvotes: 2
Views: 235
Reputation: 564671
Why is this? And isn't this exactly what garbage collection should prevent?!
The garbage collector doesn't (necessarily) run constantly. It runs as needed, and tends to not run often if there is no memory pressure. If your system has a lot of free memory, the GC will not always run frequently, so you can see memory growth. This isn't a problem - there is no issue with using "unused" memory, provided it will clean up if the system's gets into a situation where there is more memory pressure.
The garbage collector does still work, however - and you shouldn't worry about trusting it. You won't be leaking memory with pure managed code - though you may use more memory than you'd otherwise expect at times.
Upvotes: 6