Control memory usage on Forms RRS feed

  • Question

  • Hello.

    I've been developing an application in C# for Windows Mobile 6.1. I created all forms at the beginning so that the navigation could be faster, and it worked correctly. However, now I've added several forms more, and the mobile phone throws Out of memory Exceptions in several cases (when I try to open the camera or open a video with the AxWMPControl).

    I've changed the application so that it creates the forms when needed and disposes when finished, but I'm using the remote performance monitor in the powertoys and it doesn't seem to work. My forms are designed using mainly picturebox and images. If I dispose a form, picturebox and images are disposed too, or have I to implement IDisposable to dispose them by myself?

    Thank you very much.
    Monday, June 29, 2009 9:57 AM


All replies

  • Hi Enrique,

    Better dispose each and every control before you dispose your form to avoid memory leaks.

    Also check this links:


    Monday, June 29, 2009 11:16 AM
  • Hi Malleswar.

    Thanks for the information. Now I know that forms in compact framework aren't managed, and that's something that had me puzzled.

    However, I don't know if the disposing of each control is working. Using the Remote Performance Monitor, I'm monitoring "Total bytes in use after GC", because it's the only statistics which shows info about native memory in use, and although it reaches 440 K when I create my second Form, after the dispose it doesn't return to 250 K, which was the previous value. I've checked that after the dispose, the root reference in the heap has disappeared, so it should release the used memory.

    Category                 Name                                          Value      DeltaDescription
    GC                       Total Bytes In Use After GC                  449528          0The number of bytes of memory, native and managed, in use after the last Garbage Collection.

    Should I use any other statistics or tool to do the performance monitoring?

    Tuesday, June 30, 2009 7:37 AM
  • Hi, Malleswar

    Now I'm disposing each and every control as you suggested me, and It seems to work correctly. I've tried if it worked creating and disposing my forms inside a loop without receiving Out Of Memory exceptions.

    Wednesday, July 1, 2009 12:36 PM