Hoyt
December 5, 2011, 12:52am
1
I am loading a small bitmap…around 300k, in a test program…but get an out of memory error…WHY?
It works fine when I load a small, 25K sized bitmap
This is a COBRA board with megs of memory & a 20 line program
Bitmap Seeit = Resources.GetBitmap(Resources.BitmapResources.replex1_644_484);
LCD.DrawImage(0, 0, Seeit, 0, 0, 650, 480);
An unhandled exception of type ‘System.OutOfMemoryException’ occurred in mscorlib.dll
internal static Microsoft.SPOT.Bitmap GetBitmap(Resources.BitmapResources id)
{
return ((Microsoft.SPOT.Bitmap)(Microsoft.SPOT.ResourceUtility.GetObject(ResourceManager, id)));
_Dejan
December 5, 2011, 1:15am
2
Did you increase custom heap?
See this:
Hoyt
December 5, 2011, 3:22am
3
I tried it, but same error…
I just want to show a 300k bitmap, so why would that run out so quick? nothing else is going on in the program
I’ll investigate further.
_Dejan
December 5, 2011, 4:14am
4
What custom heap do you use(check what write you when you boot board)? Set it to 4MB and you will be OK.
In which line it failed?
What LCD do you use that use resolution 650x480? 7" LCD use 800x480…
Have your LCD Bitmap size 800x480?
you must know that you already have one global Bitmap with resolution 800x480 which use 1,46MB RAM and then you try load another image with resolution 650x480 which use 1,19MB RAM and if you have some big buffers you will run out of memory… You can calculate how memory bitmap use with: width X height X 4
Maybe this will run for you:
LCD.DrawImage(0, 0, Resources.GetBitmap(Resources.BitmapResources.replex1_644_484), 0, 0, 650, 480);
Hoyt
December 5, 2011, 10:40am
5
using (Bitmap LCD = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight))
{
int i;
int j;
LCD.Clear();
for (i = 0; i < 5; i = i + 1)
{
for (j = 0; j < 14; j = j + 1)
{
LCD.DrawImage(i * 200, j * 35, Resources.GetBitmap(Resources.BitmapResources.promed_wide), 0, 0, 200, 35);
}
}
LCD.DrawImage(0, 0, Resources.GetBitmap(Resources.BitmapResources.stopped_677_508), 0, 0, 600, 470);//the file is really 600x470
LCD.Flush();
Thread.Sleep(9000);
}
IS THIS what you mean…I still get the original mentioned error at the loading of the second item…even if I remove the 1st item from the program
Debug.GC(true) between dispose/loading.
Hoyt
December 5, 2011, 10:57am
7
Where exactly are you referring to?
What would this do or have an effecct on the debugging?
I threw in a few, but same result
Debug.GC(true);
using (Bitmap LCD = new Bitmap(SystemMetrics.ScreenWidth, SystemMetrics.ScreenHeight))
{
int i;
int j;
LCD.Clear();
for (i = 0; i < 5; i = i + 1)
{
for (j = 0; j < 14; j = j + 1)
{
LCD.DrawImage(i * 200, j * 35, Resources.GetBitmap(Resources.BitmapResources.promed_wide), 0, 0, 200, 35);
}
}
Debug.GC(true);
LCD.DrawImage(0, 0, Resources.GetBitmap(Resources.BitmapResources.stopped_677_508), 0, 0, 600, 470);//the file is really 600x470
LCD.Flush();
Thread.Sleep(9000);
}
Debug.GC(true) forces garbage collection
You said the error occurred [quote]even if I remove the 1st item from the program[/quote]
So I figured perhaps run the GC after to complete disposal. Did you ever update the size of your custom heap?
Hoyt
December 5, 2011, 12:05pm
9
What I showed is exactly what the help page about heaps showed to do…is there something else needed to do to set the heap?
I don’t see this
if (Configuration.Heap.SetCustomHeapSize(4 * 1024 * 1024))
{
// this will only take effect after resetting the system
PowerState.RebootDevice(false);
}
Anywhere in your code.