Hello,
I have created a .NET Cf 2.0 application which working perfectly fine however as the application is continuosly used over a few hours the program memory goes on reducing till finally at some point it gives a system error and crashes. Also after the crash the memory is not release and the application is also not running after teh crash. Only after a soft reset th memory comes back to normal size.
What could I be doing wrong
Devices tested on HX4700 (WM 5), HP 2210 (WM 2003), Dell Axim X50 (WM 2003 SE).
Hozefa

.NET CF 2.0 application occupies lot of memory
cverdon
Application.Exit() should do it (unless you have other threads running – you’d nee to make them background or terminate them manually before exit). All resources are released by the OS as your application terminates. There's pretty much no way you can keep memory after your application is gone.
You don't need to dispose of your classes unless they allocate any unmanaged resource. If you do allocate unmanaged resources, you need to implement IDisposible and call dispose on your class. Though it does not matter after your application is terminated. Even if you do have memory leak, it all will be release as soon as application exits.
If you running on WM 2003, memory is shared with files. It will go down if your application creates files. WM 5.0 has separate program and storage, so files would use storage but won't reduce program memory.
You can get WM guidelines on MSDN.
Tihomir Ignatov
Hi Ilya,
How do I exit an application I am using APplication.Exit() on the main form. The way my application functions is that is has multiple form. I have a main menu form (Application.Run(new MainMenu() This is already there in Program.cs). On clicking options in this form I open other forms as ShowDialog() cause I want them on top of main form.
Further, I have made a Library Folder where I have created managers which interact with the database class (its basically business logic that come here) for e.g.
internal sealed class PatientManager{
internal PatientManager(){
} internal void AddPatientRecord(ref Patient pStruct){
}
internal void UpdatePatientRecord(ref Patient pStruct)
{
}
etc....
}
I create an instance of this class in my Patient Form such as
PatientManager pm=new PatientManager();
Do I have do dispose this if so how do I do it Do I need to Inherit it as a component and then dispose Could this be the one blocking memory after exiting (Memory leak).
Hoping the above sample will help you understand my problem better.
Where can I get WM guide lines
Thanks
Hozefa
Vanyel
Hi Ilya,
Apologies for getting back to you a little late. However, I have managed to get a memory gain after your post. There were some duplicating imagelist and Dataset which were not getting disposed, and now I have fixed it. However, there is still a problem. When I start my cf application it occupies around 4 MB space after using it for a while and then exiting the memory is still 2 mb short i.e. before starting I have 25 mb free memory, after starting my application I have 21 mb on closing the application it shows 23 mb, only a soft reset after this bring memory back to 25 mb.
I have used some internal static methods, do you think this could be a problem if so how do I release these
If it is not the static methods do you think there are other such memory leaks which i need to fix
Tough to detect, these memory leaks!!
Thanks!!!
Jason D. Camp
My guess would be you're not really exiting the application, it's minimized instead per WM guide lines. Your application remains in memory, OS would automatically terminate it if memory would run low.
mujadaddy
You have a memory leak which you'd need to find and fix. Most common reason is not disposing of IDisposable objects allocating native resources, e.g. Bitmaps.