-
April 15th, 2015, 04:37 PM
#1
Help on Garbage Collection
Hi, Folks,
I am writing a C# addin, which calls native C++ through CLI/C++. When I keep calling the same sequence of functions many times, the GC.GetTotalMemory keeps growing even if I call GC.Collect periodically. Does anyone have any idea what might be going on?
Thanks in advance!
CR
-
April 21st, 2015, 08:50 AM
#2
Re: Help on Garbage Collection
C++ does not have a Garbage collector. If any of the code that you're writing is unmanaged it won't be garbage-collected even though you calll the GC manually. Make sure your C++ code cleans up after itself. If all you're doing is calling C++ code that someone else wrote and this is the case then they need to clean up their code. Personally I think GC encourages sloppy programming, particularly if your code needs to be high-performance. I do use it, but only when I'm certain that object clean-up doesn't have to be done in a timely manner.
Last edited by Max Peck; April 21st, 2015 at 08:55 AM.
If you think it's expensive to hire a professional, wait until you try hiring an amateur! - Red Adair
-
April 28th, 2015, 02:44 AM
#3
Re: Help on Garbage Collection
I'm going to wager that your C++ calls are allocating some native handles. For example, file handles. The .Net GC doesn't know about these resources. That means you have to clean them up yourself. This is why C# allows you to create finalizers in your classes, so when the GC is cleaning up your object, your code in the finalizer can clean up native resources.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|