

public SKBitmap GetFromBitmapList(string fileNameWithOutExt)
,A check is made in the platform specific code to see if the device is running out of memory allowed for this app and clear the bitmap list as need.
/**
* Release memory when the UI becomes hidden or when system resources become low.
* @param level the memory-related event that was raised.
*/
public void onTrimMemory(int level)
{
String info = "::" + Build.MANUFACTURER + ":" + Build.MODEL;
// Determine which lifecycle or system event was raised.
switch (level)
{
case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
/*
Release any UI objects that currently hold memory.
The user interface has moved to the background.
*/
//Toast.makeText(this, "TRIM_MEMORY_UI_HIDDEN", Toast.LENGTH_SHORT).show();
mGameView.cc.commonBitmapList.clear();
mGameView.cc.tileGDIBitmapList.clear();
break;
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
//Toast.makeText(this, "TRIM_MEMORY_RUNNING_MODERATE", Toast.LENGTH_SHORT).show();
break;
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
//Toast.makeText(this, "TRIM_MEMORY_RUNNING_LOW", Toast.LENGTH_SHORT).show();
mGameView.cc.commonBitmapList.clear();
mGameView.cc.tileGDIBitmapList.clear();
break;
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
/*
Release any memory that your app doesn't need to run.
The device is running low on memory while the app is running.
The event raised indicates the severity of the memory-related event.
If the event is TRIM_MEMORY_RUNNING_CRITICAL, then the system will
begin killing background processes.
*/
//Toast.makeText(this, "TRIM_MEMORY_RUNNING_CRITICAL", Toast.LENGTH_SHORT).show();
mGameView.cc.commonBitmapList.clear();
mGameView.cc.tileGDIBitmapList.clear();
break;
case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
//Toast.makeText(this, "TRIM_MEMORY_BACKGROUND", Toast.LENGTH_SHORT).show();
mGameView.cc.commonBitmapList.clear();
mGameView.cc.tileGDIBitmapList.clear();
break;
case ComponentCallbacks2.TRIM_MEMORY_MODERATE:
//Toast.makeText(this, "TRIM_MEMORY_MODERATE", Toast.LENGTH_SHORT).show();
break;
case ComponentCallbacks2.TRIM_MEMORY_COMPLETE:
/*
Release as much memory as the process can.
The app is on the LRU list and the system is running low on memory.
The event raised indicates where the app sits within the LRU list.
If the event is TRIM_MEMORY_COMPLETE, the process will be one of
the first to be terminated.
*/
//Toast.makeText(this, "TRIM_MEMORY_COMPLETE", Toast.LENGTH_SHORT).show();
mGameView.cc.commonBitmapList.clear();
mGameView.cc.tileGDIBitmapList.clear();
break;
default:
/*
Release any non-critical data structures.
The app received an unrecognized memory level value
from the system. Treat this as a generic low-memory message.
*/
break;
}
}
if (gv.mod.loadedTileBitmaps.Count > 400)
{
try
{
foreach (Bitmap bm in gv.mod.loadedTileBitmaps)
{
bm.Dispose();
}
//these two lists keep an exact order so each bitmap stored in one corrsponds with a name in the other
gv.mod.loadedTileBitmaps.Clear();
gv.mod.loadedTileBitmapsNames.Clear();
}
catch
{
}
}
if (gv.mod.loadedTileBitmaps.Count > 250)
{
int cullNumber = ((gv.mod.loadedTileBitmaps.Count / 10) + 2);
try
{
if (gv.mod.loadedTileBitmaps != null)
{
for (int i = 0; i < cullNumber; i++)
{
gv.mod.loadedTileBitmaps[i].Dispose();
gv.mod.loadedTileBitmaps.RemoveAt(i);
gv.mod.loadedTileBitmapsNames.RemoveAt(i);
}
}
//these two lists keep an exact order so each bitmap stored in one corresponds with a name in the other
}
catch
{
//addLogText("red", "caught error");
}
Return to General IceBlink Project Discussions
Users browsing this forum: No registered users and 1 guest