I was doing some bitmap loading, using some predefined bitmaps (resources)…this has led to an out of memory conditon…I do have a solution, but want to understand the problem & see if there is an alternate fix …note the large heap HAS been set:
private static Bitmap tiled;
public static void setupSplash() //splash screen, first one shown
{
splash.Backcolor = Skewworks.NETClix.Colors.Blue;
if (tiled==null) tiled = new Bitmap(800, 480);
int i;
int j;
for (i = 0; i < 6; i++)
{
for (j = 0; j < 14;j++)
{
tiled.DrawImage(i * 160, j * 34, Resources.GetBitmap(Resources.BitmapResources.Chevy), 0, 0, 160, 34);
}
}
splash.BackgroundImage = tiled;
This is being called in a loop that should released it, but the memory goes down , down down, til an out of memory occurrs:
int ppp = 0;
while (true)
{
ppp++;
Debug.Print(" splash scrn " + ppp);
setupSplash(); //do it over & over to investigate memory issues
splash.Dispose();
Debug.GC(true);
}
GC: 16msec 8749848 bytes used, 97080 bytes available
Type 0F (STRING ): 276 bytes
Type 11 (CLASS ): 23256 bytes
Type 12 (VALUETYPE ): 396 bytes
Type 13 (SZARRAY ): 1140 bytes
Type 15 (FREEBLOCK ): 97080 bytes
Type 17 (ASSEMBLY ): 25008 bytes
Type 18 (WEAKCLASS ): 96 bytes
Type 19 (REFLECTION ): 216 bytes
Type 1B (DELEGATE_HEAD ): 432 bytes
Type 1D (OBJECT_TO_EVENT ): 216 bytes
Type 1E (BINARY_BLOB_HEAD ): 8673624 bytes
Type 1F (THREAD ): 1152 bytes
Type 20 (SUBTHREAD ): 144 bytes
Type 21 (STACK_FRAME ): 2124 bytes
Type 27 (FINALIZER_HEAD ): 18744 bytes
Type 31 (IO_PORT ): 180 bytes
Type 34 (APPDOMAIN_HEAD ): 72 bytes
Type 36 (APPDOMAIN_ASSEMBLY ): 2772 bytes
Failed allocation for 912 blocks, 10944 bytes
#### Exception System.OutOfMemoryException - CLR_E_OUT_OF_MEMORY (1) ####
#### Message:
#### System.Resourc
instead of using resources.getbitmap…in the statement itself, I defined it as static ahead of time:
static Bitmap testit = Resources.GetBitmap(Resources.BitmapResources.Chevy);
private static Bitmap tiled;
public static void setupSplash() //splash screen, first one shown
{
splash.Backcolor = Skewworks.NETClix.Colors.Blue;
if (tiled==null) tiled = new Bitmap(800, 480);
int i;
int j;
for (i = 0; i < 6; i ++)
{
for (j = 0; j < 14; j++)
{
tiled.DrawImage(i * 160, j * 34, testit, 0, 0, 160, 34);
}
}
MAN, what a speed difference! I could now barely read the debug screen flying by & the memory levels stay “steady” & never an error. …didn’t realize it would make a difference…but what about the original setup? WHY does it use more & more memory & can you prevent it with that edit, by somehow releasing the resource? Or is it just wise to make everything staitc as in the second method?