locked
How handle Out of memory exception? RRS feed

  • Question

  • hi,

     i am dynamically add some picture box and link label in panel. when i run the program i got "out of memory exception" to handle this exception i try "dispose()"  method to release memory of object. but when i try dispose method i got another exception that is "object disposed exception was un handled".

    how solve this problem please help me.


    thanx,
    Tuesday, November 17, 2009 10:59 AM

Answers

  • First you should handle the WM_HIBERNATE message for when the system sees that it is approaching a low memory condition.

    Second you should consider th euncompressed size of the image you are using.  The uncompressed size will typically be around width*height*3 bytes for a 24-bit image. On Windows Mobile each process is limited to 32 megabytes. So it's not hard for an image to use up all of your processes available memory.


    Joel Ivory Johnson
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    • Proposed as answer by Michael Koster Tuesday, November 17, 2009 10:33 PM
    • Marked as answer by ZHE ZHAO Monday, November 23, 2009 4:44 AM
    Tuesday, November 17, 2009 3:17 PM

All replies

  • First you should handle the WM_HIBERNATE message for when the system sees that it is approaching a low memory condition.

    Second you should consider th euncompressed size of the image you are using.  The uncompressed size will typically be around width*height*3 bytes for a 24-bit image. On Windows Mobile each process is limited to 32 megabytes. So it's not hard for an image to use up all of your processes available memory.


    Joel Ivory Johnson
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    • Proposed as answer by Michael Koster Tuesday, November 17, 2009 10:33 PM
    • Marked as answer by ZHE ZHAO Monday, November 23, 2009 4:44 AM
    Tuesday, November 17, 2009 3:17 PM

  • Thank You for give me reply,

       i am load image in bitmap from resources. when i load it first time it run well. but when i call below function  5- 7       time it   give me  exception out of memory. i used dispose method to free memory but it still give OOM exception.
     here some code that i am used. image size is 480*800.


     public Bitmap SetNewImage(int Theme_No)
    {

    if (mtmp!= null)
    {
    mtmp.Dispose();
    }

    Resource1.ResourceManager.ReleaseAllResources();
    GC.Collect();
    switch (Theme_No)
    {
    case 1:
    if (Resource1.image1!= null)
    {
    Resource1.image1.Dispose();
    }
    mtmp= Resource1.image1;
    GC.
    break;
    case 2:
    if (Resource1.image2!= null)
    {
    Resource1.image2.Dispose();
    }
    mtmp= Resource1.image3;
    break;
    case 3:
    if (Resource1.image3!= null)
    {
    Resource1.image3.Dispose();
    }
    mtmp= Resource1.image3;
    break;
    case 4:
    if (Resource1.image4!= null)
    {
    Resource1.image4.Dispose();
    }
    mtmp= Resource1.image4;
    break;
    }

    Resource1.ResourceManager.ReleaseAllResources();
    GC.Collect();
    return mtmp;
    }
    Monday, November 23, 2009 1:08 PM
  • What are the dimensions of your image files? 
    It takes all the running you can do to stay in one place.If you want to get somewhere else,you must try to run at least twice as fast as that.
    Monday, November 23, 2009 1:53 PM