locked
Out of Memory Exception for Windows Mobile 6.1 RRS feed

  • Question

  • Hi,

    I have this error from my Windows Mobile 6.1 when running my NetCf2.0 app.  I have tested this NetCF 2.0 App in my Windows mobile 5.0 and I dont have this error.

    How do I fix this?

    Thanks



    Peace is the fruit of Love
    Thursday, May 7, 2009 8:32 AM

Answers

All replies

  • Hi,

    Can you provide a little more detail regarding the code you are running, maybe provide some example of the code you are executing.

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Thursday, May 7, 2009 8:37 AM
  • Hi BinaryWave,

    Please try to increase memory on emulator and try the same.

    Increasing emulator RAM size - this can be done before starting the emulator.  Choose "tools->options" menu.  In "options" dialog choose "Device Tools->Devices".  This will display the platforms and devices.  Choose PPC 5.0 emulator and click on "Properties".  This will open up another dialog.  Click on "Emulator options...".  Under "General" tab you can specify the RAM size. 

    Please let us know more details, if you still get the same exception after increasing memory.

    Regards,
    Malleswar

    Thursday, May 7, 2009 8:43 AM
  • Hi both,

    There is Enough memory in this new Mobile 6.1. I was just doing some photo sketching or drawing on the photo which loaded in the pictureBox.

    The NetCF version is 2.0.7045.0 for this Windows mobile 6.1.

    thanks

     


    Peace is the fruit of Love
    Thursday, May 7, 2009 9:04 AM
  • Hi BinaryWave,

    Try to use remote performance tool and check you memory up and downs while your application is running.

    Performance Tools:

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1616497&SiteID=1


    Regards,
    Malleswar

    Thursday, May 7, 2009 9:09 AM
  • Hi Malleswar,

    I have checked that the windows mobile 6.1 has 45 MB free memory.

    I even have the same error Msg when I load the photo from the Folder My Picture. here the code:


     

    Try
    Dim bmp As New Bitmap(StrFile)
    Dim img As System.Drawing.Image

    img = bmp

     

    If img.Width > img.Height Then
    LbCharTTL.Text = "Characters:200"
    WordCount = 200

     

    Else

    LbCharTTL.Text = "Characters:160"
    WordCount = 160

     

    End If

    Pic.Image = img
    Pic.SizeMode = PictureBoxSizeMode.StretchImage

    Catch ex As Exception

    MessageBox.Show(

    "Draw error: " & ex.Message)
    End Try

    anything wrong with the code? memory not enough?

    For my windows 5.0, I dont have this problem.

    Please help.




    Peace is the fruit of Love
    Thursday, May 7, 2009 11:37 AM
  • Hi,

    How many bytes is the image itself?

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Thursday, May 7, 2009 11:46 AM
  • hi Paul,

    It is 27 kb. a very small file jpg .
    Peace is the fruit of Love
    Thursday, May 7, 2009 12:00 PM
  • Hi,

    You have to bare in mind that the JPG is uncompressed (bitmap) when it is opened in code.

    Does the OOM exception occur the first time you execute your code or after a number of executions of the code you posted?

    Also you have to bare in mind that your code will execute within a 32MB virtual memory process slot, which could be dramatically reduced if other applications are running or you load a lot of images into memory via code. Therefore your device may have a large amount of RAM available however your application can not make full use of this due to the virtual memory limitation of Win CE 5 based operating systems such as Windows Mobile 6.1. Your WM5 device may have a lower number of other applications running.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Thursday, May 7, 2009 12:16 PM
  • Hi,

    Thank for the info on jpg and Virtual memory.

    This mobile phone  is OMNIA from Samsung. And I dont know how many programs are running when I turn on the phone.

    This  is what happened:
    1) Launch my NetCf Application. and  click a button  to load photo from My Picture folder and do some drawing later.


    The error Msg occurs the first time  as soon as I click the button to load photo into the pictureBox.

    - Close the program and try again.  Same thing happen.


    is there something I can do or is it the NetCF Missing some component in GDI?

    Thanks

     


    Peace is the fruit of Love
    Thursday, May 7, 2009 1:07 PM
  • Hi,

    You might want to have a look at this application :-

    http://www.codeproject.com/KB/mobile/VirtualMemory.aspx

    It will show you the virtual memory distribution of your device to see a, what other applications are running and b, how much virtual memory you have available.

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Thursday, May 7, 2009 1:32 PM
  • Hi BinaryWave,

    Try to close all the running programs from Task manager(WM 6.1 devices)  and try to reset your device. Then try again with your application.


    Please let us know if it still gives problem.


    Regards,
    Malleswar
    Thursday, May 7, 2009 1:33 PM

  • Hi Malleswar and Paul,

    You are right on. You showed me where to find the the problem occur.I followed your instruction to use Task manager to end all programs and re-launch my netCf-Application.
     
            the result :      it worked  a brief moment BUT showed the SAME  error MSg


     This is what I discovered when I looked at the Task manager after Closing my NetCf_Application.

     I see all the WinForms are loaded in this TasK manager Window

     The Task Manager record all my Movement:

     1) when I open my NetCf Application and task manager will show

     - It shows the first WinForm I open
     - It show the 2nd winform which use to select Photo from My Picture folder
     - it shows the 3rd Windorm which used to draw photo


     2) show Other programs like file explorer that I used


     These will take up a sizeable memory.


     Question:

     1) This is NetCF Application, How we know when and how much memory is required ???
     
     2) Show me how Can I destroy the 2nd form and 3rd form  when I open the Fourth WinForm? may be this will reduce the
        usage of memory.

    3) I have to launch my program from program files, this is why I used File explorer. This will use up memory?

     4) Is this memory thing  the real problem?


     Thanks

     


    Peace is the fruit of Love
    Thursday, May 7, 2009 2:16 PM
  • Hi BinaryWave,


    1) To monitor you memory occupation in your application( for each part), use the Remote permance monitor. So that you can control and can work accordingly

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1616497&SiteID=1

    2) Your first form is parent form and other rest of form will be child forms. Try to always close the child forms when the work is finshed and come back to your parent form


    3) To manage your forms, use single ton pattern.  So that only one instance will run for each form

    4) If you dont maintain memory in correct way, you system will crash or slow downs the device performance when your application is running.


    Please let us know if you have any queries regarding this.


    Regards,
    Malleswar
    Thursday, May 7, 2009 2:23 PM
  • Hi Malleswar,

    Thank you both so much for helping me to troubleshoot this problem.

    I will work on reducing child forms .  is singleton means allowing One Winform loaded for processing?

    Will let you know the result. Need a break now.
    Peace is the fruit of Love
    Thursday, May 7, 2009 2:33 PM
  • Thursday, May 7, 2009 2:41 PM
  • Hi BinaryWave,

     is singleton means allowing One Winform loaded for processing?

    Yes yor are correct. Even when you are reopening the form, it will check for the existing instance and creates if it is not available.

    Simple way of using single ton( to create the form instance at one place):

    private

     

    static Form1 _form1;

     

    public static Form1 GetForm1()

    {

     

    if (_form1 == null)

    _form1 =

    new Form1();

     

    return _form1;

    }


    Becuase of this multiple instances of the same form will not run for your application.

    Please let me know if you have any queries regarding this.


    Regards,
    Malleswar

    Thursday, May 7, 2009 3:02 PM
  • hi Malleswar,

    Just need some opinion on the Out of memory issue. I think efficiently use of memory is important.  So, I like to know  the below questions.

    1) On the top right corner of the form , which button will close and dispose the form from the memory:      Button with OK  or Button with [x]  .This means form obj is no longer in existence in the memory.

     1a) will Button with [x] close and dispose the form from memory..

    1b) will button with OK close and dispose the form from memory.

    2) is this way will save memory space:  Open the target form and close current-form instead of using singleton? sometimes, I need two forms in the memory to do tasks.

    3) How do I capture the Form Close Event. So , I can do some checking?

    Thanks

     


    Peace is the fruit of Love
    Friday, May 8, 2009 7:09 AM
  • Hi,

    The following blog entry might be worth reading :-

    http://geekswithblogs.net/lvega/archive/2006/11/11/96824.aspx

    Hope this helps.

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Friday, May 8, 2009 7:57 AM
  • Hi BinaryWave,


     1a) will Button with [x] close and dispose the form from memory..

    General behavior of this is to minimize. It does not dispose the object


    1b) will button with OK close and dispose the form from memory.

    General behavior of this is to close.

    This also does not dispose the form immediately( as per my observation, not sure), to dispose you can dispose through your code.


    2) is this way will save memory space:  Open the target form and close current-form instead of using singleton? sometimes, I need two forms in the memory to do tasks.

    your parent form should always be open and you can open and close your child forms.


    3) How do I capture the Form Close Event. So , I can do some checking?

    When you us OK --> you will get get form closing , form closed events for this

    [X] --> no events will be raised


    Regards,
    Malleswar
    Friday, May 8, 2009 8:36 AM
  • Hi Malleswar,

    My concern is NOT to over use the memory. Because I afraid over use of memory will ---freeze the mobile phone.

    1) How do I dispose the form obj through code as you suggested?
     - isn't it by clicking  Button OK means closing and disposing the form?
      If not, Do you mean using form Close events? But Form has Event for Closed and Closing. Which one serves the      purpose?

     Private sub Form_Closed( o as object, e as eventArgs)

      // this call  will dispose the form obj?
      me.close

     end sub

     or  Form_Closing()


    2) Open parent form and closing child form .yes, I follow you. I use the parent Form as the main Menu.

     
      Parent Form---->Child Frm1 -----> Child frm2 
                            in Frm1:
                           Open Child frm2
                           Close Child Frm1 

        in child Frm1: Are these actions equal to dispose Child frm1? So the memory has Parent Form and Child frm2?   Is this way will save memory being over used?

    3)  say I want to capture when the user click the Button with [x] or with OK dynamically. That means I did not code in the form close event  like above (1) .How?

       This way  I can check the form object if it is still there or not.
     
          Child Frm 1 -------------------------------->   Child Frm 2.
     
        open and pAss Frm1 obj to frm2
        Close frm1

                                                                     When close Frm 2

                                                                     Check Frm1 is still there in memory?


    Thanks



      


     


     


    Peace is the fruit of Love
    Friday, May 8, 2009 9:23 AM
  • Hi BinaryWave,

    1) How do I dispose the form obj through code as you suggested?
     - isn't it by clicking  Button OK means closing and disposing the form?
      If not, Do you mean using form Close events? But Form has Event for Closed and Closing. Which one serves the      purpose?


    As I observed they dont dispose the form immediately in few cases.

    Refer thsi link: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.close.aspx

    So better always you dispose the child forms when ther are not used, this is good instead of waiting for CLR to dispose your form object.

    Forms can be disposed   bye just calling dispose() method.   formname.dispose();

     in child Frm1: Are these actions equal to dispose Child frm1? So the memory has Parent Form and Child frm2?   Is this way will save memory being over used?

    Can you explain more about this?

    3) I can simply suggest    Try to use LIFO( Last in First out) that means you have to close the last opened form first and in the order.


    Please let me know, if my explanation give you the solution.


    Regards,
    Malleswar
    Friday, May 8, 2009 4:05 PM
  • Hi Malleswar,

    Sori to take up so much of your time to help up. Really appreciate your help and understanding.

    Good news. It appears working.
    close form that are not required. After running the netCF_app, I check the Task Manager,I found No child Form were left behind ( Clean up) .One thing left is the NetCF_application itself even I have close the Parent Close ( button with Ok) . I guess this is norm.


    The Out Of memory Issue still there.

    The last time was that this caused the phone "Freeze" .  Now, It wont Freeze.

    This is what I think:

    1. The touchScreen of Omnia 6.1 is too Sensitive and consume much resource as compare my Hp 5.0


    If the same Skecthing or Pen drawing Code used in Hp 5.0 and work, I think it should work in Omnia 6.1.  BUT it work with OOM and Hp with no OOM.

    I will check again and inform .


    Hey, realli appreciate your help.

    thank





    Peace is the fruit of Love
    Saturday, May 9, 2009 2:56 AM
  • Are you displaying your dialogs by using the Show() method or the ShowDialog() method?

    After you've displayed the dialog are you setting the variable that referenced it to null?

    Joel Ivory Johnson
    Saturday, May 9, 2009 3:15 AM
  • Hi Joel,

    I am using   frm.Show() method. 

    Set gx as graphics for global level.  use gx  graphics in  Mouse Event but didnot dispose it after use . Dont seems to see any null variable.

    Will PictureBox.Refresh() use alot of memory?

    Thanks
    Peace is the fruit of Love
    Saturday, May 9, 2009 3:51 AM
  • Hi Binary,

    Will PictureBox.Refresh() use alot of memory?
    You need to check this by using remote perfomance monitor.
    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1616497&SiteID=1

    Generally loading the images from resources takes more time than loading images from files.  Thas why I always used to prefer to load the images from file until unless its compulsory to load the image from resource.

    Please let me know if you have any queries regarding this.

    Regards,
    Malleswar

    Saturday, May 9, 2009 10:54 AM
  • Hi Malleswar,

    Thank you guys for info on : 32Mb virtual memory and Image Handling tips in this forum. I work on this aspect.

    Finally, the windows 6.1 wont freeze anymore. I have reduced image size before handling  the Image and clean up after used and Dont use PictureBox.refresh. ( the link is not working). It work much quicker and smoother.

    However, OOM still happen BUT less for this OMNIA 6.1.  When OOM occurs, I check with End task Manager, this time there are no Child forms.After exiting OOM in TRY Statement, It will work again as NORMAL.

    Still trying to find solution to eliminate this OOM totally.


    Thanks
    Peace is the fruit of Love
    Sunday, May 10, 2009 10:40 AM
    • Marked as answer by warrentang Wednesday, May 13, 2009 2:08 AM
    Sunday, May 10, 2009 3:10 PM
  • Hi Paul Diston,

    Thank u thank u for the very useful article links.  It really make me understand better or 32MB Vs 2GB.

    further digging, saw article mention window 7.0 will solve all this 32 Virtual Memory issue. So glad to hear this.

    By the way, for non-window 7.0, we have to stick with the solution mentioned in your Link.

    Is there any example to follow to learn to use the feature?



    Thanks
    Peace is the fruit of Love
    Monday, May 11, 2009 6:41 AM
  • You may also check all the suggestions I wrote in my post http://blogs.msdn.com/raffael/archive/2008/02/21/netcf-memory-leak-now-what.aspx.
    Thanks,
    ~raffaele
    http://blogs.msdn.com/raffael

    This posting is provided 'as is' with no warranties and confers no rights.
    • Marked as answer by warrentang Wednesday, May 13, 2009 2:08 AM
    Tuesday, May 12, 2009 3:35 PM
  • Hi,

    I am facing similar problem in window mobile 6.5  in the device, can I increase the memory. if so kindly guide me how to do it.

    Regards,

    Yadu

    Friday, January 25, 2013 11:07 AM