-
July 11th, 2011, 03:00 PM
#1
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:
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.
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);
}
}
}
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.
Last edited by Ciralia; July 11th, 2011 at 03:18 PM.
"My software doesn't have bugs, it just develops random features."
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
|