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:
System.WeakReference
System.Hastable.bucket[]
System.Windows.Forms
GCHandle
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.Code:public class Gui
{
// Variables
private MyFormClass myFormVariable = null;
private System.Collections.ArrayList myArrayList = new System.Collections.ArrayList();
// Constructor
public Gui()
{
System.Collections.ArrayList localArrayList = new System.Collections.ArrayList(myArrayList);
object myObject = new object();
myArrayList.Add(object);
myFormVariable = new MyFormClass();
MyMethod();
}
private void MyMethod()
{
System.Drawing.Point myPoint = new System.Drawing.Point (34, 3);
char[] c = new char[2];
c[0] = 'c';
if (myFormVariable != null)
{
myFormVariable.Location = myPoint;
myFormVariable.Name = new string (c);
}
}
}

