Application uses too much memory
I'm working on a Pocket PC application in VS 2003 (C#).
I'm working with a database(collecting, inserting data). The application has several screens.
While testing I noticed that the application constantly uses more and more memory while I navigate from one screen to another several times.
I used some threads. I thought that mismanaged threads are the problem and removed them for testing. Even without using threads the used memory increases.
Even if I quit the application the used memory is not freed(?!!!!).
Could someone give me some hints of where the problem might be?
I tested a little more and I found new questions.
A) Should I override the dispose method for the screen objects(all the objects ) I use?
Because at the moment I don't do so.
B) Is there a problem with the next approach(I'll give some test code sample)
The main form contains a control and the control has a button. When the button of the control is clicked, in the handler, a method of a singleton class it is called wich removes the current control object, instantiates a new one and adds the new one to the main form.
Is there a problem for the current control to be removed indirectly(through the singleton method)from the main form, in the handler for its own button.
//method from the singleton class.....
public void RemoveAndAdd()
{
mainForm.Controls.Remove(mainForm.myControl);
mainForm.myControl = new ClassControl();
mainForm.Controls.Add(mainForm.myControl);
}
//........
//the class of the control wich is added to the mainForm
public class ClassControl : Control
{
private Button _btn = new Button();
//private Bitmap someImage;
public ClassControl()
{
_btn.Bounds = new System.Drawing.Rectangle(20,20,100,100);
_btn.Click +=new EventHandler(_btn_Click);
this.Controls.Add(_btn);
}
private void _btn_Click(object sender, EventArgs e)
{
Singleton.Instance.RemoveAndAdd();
}
}
Singleton class knows about the main form like this : "Singleton.Instance.MainForm = this;"
C) My PocketPC has a memory visualizer. I run some tests and I noticed something.
It shows me 30MB free program memory after reset. I run a program or two and I noticed that even if I exit the application it doesn't bother to clean up all the memory the application used. Looks like 15MB free memory is enough for him. It cleans till gets 15MB ree memory and stops. Why?....
Well, I found be very, very pleased if someone would help me with some answers...
Thank you

