What is the hidden  considerations to avoid memory leak in CF2.0  applications

Posted on 2011-04-25
Last Modified: 2013-12-27
I am using VS2005pro / /Windows mobile 6.0  SDK  to develop my applications , usually my application have a memory leak problem , and I solved this problem by closing my application and started again , some time it need to restart the windows also after 10 hours of running.
I am using   GC.Collect  to free the memory in my application and disposing the objects and using = Nothing …etc.
What is the hidden  considerations to avoid memory leak in CF2.0  applications or I missed ?
Question by:DODO
    LVL 11

    Expert Comment

    1. Certain constructor overloads for XmlSerializer leaks resources. A dynamic assembly is being created serialize or deserialize the object and you cannot unload the assembly (unless you are using app domains). A better way around this is to cache any serializers that you create for a specific type.

    2. If you use Activator.CreateX and adding those objects to a collection (List or Dictionary) then you must clear the collection if you ever new it up again. Items in the collection are not dereferenced because they where created dynamically so the GC never picks them up unless they were specifically removed or the Clear method is called.

    Maybe now is a good time to learn how to use a memory profiler like .NET Memory Profiler. You get a 2 week trial to figure it out. Just look for object instances that are growing out of control and investigate the code (you can easily jump to offending areas from the profiler) to see why it is leaking.

    Later version of VS come with much better performance monitoring but since your on 2005 you'll have to rely on external tools that have evolved from way back then.

    .NET memory leaks are usually very hard to find without the right tools but the two areas I highlighted are the most common pitfalls I've seen. I would also suggest avoiding your own calls to GC.Collect especially when you are testing for the leak. The more you call it the more likely you'll get false positives with what the GC cannot deal with.

    Good luck!

    Author Comment

    Dear brutaldev
    Actually I have VS2010 Pro recently, and not used yet ,because  it’s not  supporting WM6.5 as VS2005 & VS2008  , Do you think there is a way to use it to monitor memory leak in windows mobile applications?
    Best Regards
    LVL 11

    Accepted Solution

    You're just out of luck, Premium and Ultimate version of VS2010 come with the profiling capability (product comparison under Debugging and Diagnostics: and I'm not even sure if it supports profiling for older versions of WM.

    You're not completely out of luck though, EQUATEC have a profiling tool that will profile WM apps amongst other things but it's not amazing (worth a try though). A couple more tools (including the one above) have been mentioned in this question, take a look and see if anything there can assist you.

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Let me explain this picture a little bit.  First, in case you haven't already guessed, you are looking at my 2 phones, an Android Samsung Galaxy S5 on the left and an iPhone 5 on the right.  They are on their respective cradles on my desk.  But, you…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now