If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Solving Memory Leaks

I have a program that runs C++ for its behind-the-scenes functional operations and runs C# for its GUI portion, however, the C# GUI executable has a memory leak issue and I'm trying to track it down. The memory of the program gradually increases over time, eventually handicapping the PC. I ran .NET Memory Profiler and the items that used the most memory were:

Since these are system items, this leads me to believe that I'm using them incorrectly in my code. That being said, here are some samples of code which I believe to be suspect for memory leaks, but I'm not sure if there is a way or how to fix them.

Will any of these variable initializations/usages cause memory leaks? If so, how do I fix it? Of course I just gave a sample code snippet...these types of initializations are all over the code I'm working with.

Re: Solving Memory Leaks

Hi,
Your information is incomplete atleast for me. However, from whatever you have posted, I can tell you that there is probably a resource leak in the form of GDI object. May be some sort of object belonging to System.Drawing or similar and which is not freed. The reason for that is the lines in your post:

A weakReference is a class that is used by Garbage Collector (GC) to maintain a track of objects which might be referenced even after they are listed as candidates for collection after being dereferenced. When GC tries to get a handle to the resource, it fails. Also, when you say that the problem is in the C# application, please make sure that you are performing marshalling correctly. If you can look at the MSIL code generated using ILDASM, even better. Also, are the Forms and UI a part of the managed code?
May be you can now look for other sources that can cause the error and post the info here...so that some one will gladly help you
Good luck!
Bhushan