regarding memory exception

hi ,
i have been in developing application in smartphone using c# .. i am using visual studio 2005 .... for my application i have loaded the resoueces using the following code ...
Stream s ;
Bitmap img_btYellow;
s = this.GetType().Assembly.GetManifestResourceStream("Widgets.res.avblue.png");
img_btYellow = new Bitmap(s);
s.Close();

i have loaded 8 '.png' images through the above code using the same stream ' s ' . the application is running fine in emulator .... but it is showing out of memory exception in the exe created inside the bin folder ... even i tried using singleton object for all the classes , that i have used .. but it s still showing the same exception .. could anyone help me in resolving this issue ..




Answer this question

regarding memory exception

  • JoshKorn

    You have to dispose of all these bitmaps as soon as you done using the. Also keep in mind bitmaps are expanded into memory potentially taking huge amounts of RAM. Small 100K JPEG or PNG can be expanded to megabytes in RAM. Considering devices are limited to 32 MB (~25 available for application) of virtual RAM that would lead to OOM exception very quickly. Consider scaling these bitmaps down to, say. VGA resolution to save RAM.



  • Bruno Ribeiro

    You should only dispose of something you no longer need. If you dispose of bitmap you would have to recreate it if it's needed again.

    If it's a game tiny QVGA (or at best VGA) bitmaps should be used. Scale down all your bitmaps to that resolution to save memory and improve performance.

    As to flickering, search for "double buffering", that’s the technique you’d need to use. It’s been discussed quite a few times.



  • is98

    hi ilya ,
    so there is no other way than double buffering in order to control flickering. wheather the .NET compact frameWork is bilt upon double buffering . if so how to implement double buffering in our application


  • Jason Jaegers

    Moving to Smart Devices General forum where it has got better chances of being answered.

    -Thanks,

    Mohit


  • Aleniko29139

    hi Ilya,
    i had even tried with Double buffering concept . still the screen is flickering in the emulator .
    thanks
    sadiq


  • Corby111

    thanks Tumanov . actually i have been involved in game development . so i ll be using the bitmaps oftenly . if i dispose how can i use it back .moreover in my game , eventhough i have used a single refresh () throughout my application , while handling keyactions , the screen is flickering .i have to sort out this problem . if not i cannot proceed . i have searched throughout the web , but i cannot find the suitable solution.
    thanks
    sadiq


  • Hoodwinked

    thanks Ilya. i had avoided flickering through overiding OnpaintBackground() method.

    thanks sadiq


  • Troy Lundin

    There are many game samples available, go through them and see how they deal with this issue, then do the same.



  • regarding memory exception