Out of Memory Exception Error on Load

Discussion in 'Questions (Windows Mobile)' started by willisgt, Feb 29, 2008.

  1. willisgt

    willisgt Active Member Licensed User

    I am having a problem with a rather large application. When we try to run the executable on a 640x480 VGA device (an HTC Advantage or an iPaq 210 Enterprise), we get an Out of Memory Exception error.

    This error does not occur on QVGA devices like the HTC 8925/AT&T Tilt.

    I have narrowed the problem down to the number of forms the program has to deal with at launch. It can't handle more than 40 forms. To verify this, I created a new application that does nothing more that start up and display Form1. Then I added Form2 through Form40 (40 forms total). I compiled the executable, for the device, with optimization on, loaded it onto the VGA device, and launched it. It crashed without even displaying Form1 and reported the Out of Memory Exception error.

    I then recomplied the same application with optimization off, loaded it onto the VGA device, and launched it. The program ran properly.

    I just can't beleive that this program is chewing up more than 70 megabytes of free program memory and still wanting more.

    So I have to do one of the following:

    1.) Find a way to allocate more memory to the program.

    2.) Strip forms out of my program until I'm under the limit. (The users probably won't appreciate the loss of program functions that would accompany this option.)

    3.) Compile my program non-optimized, which I'm having problems doing. I use about a dozen DLLs, and I'm not sure which ones are protesting in a non-optimized compilation.

    4.) Become a welder.

    Anyone have any thoughts on this?


  2. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Hi Willisgt,

    I've not come across this problem before, but then I've not come across an aplication that needed 40 forms.
    If the problem is indeed the number of forms, which you seem to have prooved that it is then the only option is to use less forms ;)
    This doesn't mean that you need to lose any functionality though. You will probably need to add forms in runtime and then dispose of them when you've finished with them. This will free up memory, so you can continue with your aplication.

    Ps if you can post your code then myself and the others here on the forum may be able to point out a better way of doing it (I'm only an amateur but there's a lot of knowledge around the forum)

  3. Erel

    Erel Administrator Staff Member Licensed User

    Small correction, you can't dispose of forms (whether created at runtime or not).
  4. willisgt

    willisgt Active Member Licensed User

    I appreciate the offer, but it's not practical to post the code. One, it's 17,000+ lines long. Two, my employer would probably object to my posting the code.

    I expect that you're right - I'm going to have to build at least some of the forms dynamically, preferrably the simpler ones. I just hope I don't run into another memory error as a result of trying to dynamically populate a blank form.


  5. willisgt

    willisgt Active Member Licensed User

    One really dumb question...

    I'm making a grand assumption that if the mobile device that's having the memory problem simply had more memory, I wouldn't be having this problem.

    Since I know very little about how .Net works, I'm cautious about just going out and getting a memory upgrade without knowing.

    Is there an upper limit to the amount of memory that .Net will allocate for itself? Or will it use whatever it can up to the limit of available memory?


  6. Erel

    Erel Administrator Staff Member Licensed User

    More memory will probably help but I can't say for sure.
    I recommend you to use more Panels or TabControls instead of forms or use the nonoptimized compiler. All libraries (except of agraham's threading library) work with the nonoptimized compiler.
  7. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Sorry about that.... think that I may have fallen into this trap before as it is documented in the help as having a dispose method.

  8. Erel

    Erel Administrator Staff Member Licensed User

    :signOops: The documentation will be fixed.
  9. agraham

    agraham Expert Licensed User

    I believe it is building all the forms on start-up, and 40 VGA size form bitmaps take lots of memory even before controls are added to them! However I don't understand why the non-optimised compiler does not suffer this effect (Erel?) :confused:

    What are they protesting about? :)

    EDIT :- Sounds like a truly epic program!
    Last edited: Mar 1, 2008
  10. Erel

    Erel Administrator Staff Member Licensed User

    The non-optimised compiler doesn't create real 640 * 480 VGA forms and therefore each form consumes less memory.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice