resource cleanup fixed

This commit is contained in:
Vadim Lopatin 2014-03-18 15:43:42 +04:00
parent e76394c5da
commit abb5417819
5 changed files with 70 additions and 35 deletions

View File

@ -40,6 +40,8 @@ extern (C) int UIAppMain(string[] args) {
// create window // create window
Window window = Platform.instance().createWindow("My Window", null); Window window = Platform.instance().createWindow("My Window", null);
static if (false) {
LinearLayout layout = new LinearLayout(); LinearLayout layout = new LinearLayout();
layout.addChild((new TextWidget()).textColor(0x00802000).text("Text widget 0")); layout.addChild((new TextWidget()).textColor(0x00802000).text("Text widget 0"));
layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget")); layout.addChild((new TextWidget()).textColor(0x40FF4000).text("Text widget"));
@ -79,6 +81,9 @@ extern (C) int UIAppMain(string[] args) {
layout.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT); layout.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
window.mainWidget = layout; window.mainWidget = layout;
} else {
window.mainWidget = (new Button()).text("sample button");
}
window.show(); window.show();
window.windowCaption = "New Window Caption"; window.windowCaption = "New Window Caption";

View File

@ -699,11 +699,17 @@ class SolidFillDrawable : Drawable {
class ImageDrawable : Drawable { class ImageDrawable : Drawable {
protected DrawBufRef _image; protected DrawBufRef _image;
protected bool _tiled; protected bool _tiled;
private int _instanceCount;
this(ref DrawBufRef image, bool tiled = false, bool ninePatch = false) { this(ref DrawBufRef image, bool tiled = false, bool ninePatch = false) {
_image = image; _image = image;
_tiled = tiled; _tiled = tiled;
if (ninePatch) if (ninePatch)
_image.detectNinePatch(); _image.detectNinePatch();
Log.d("Created ImageDrawable, count=", ++_instanceCount);
}
~this() {
_image.clear();
Log.d("Destroyed ImageDrawable, count=", --_instanceCount);
} }
@property override int width() { @property override int width() {
if (_image.isNull) if (_image.isNull)

View File

@ -475,7 +475,7 @@ class FreeTypeFontManager : FontManager {
return best; return best;
} }
private FontList _activeFonts; //private FontList _activeFonts;
private static FontRef _nullFontRef; private static FontRef _nullFontRef;
@ -490,13 +490,14 @@ class FreeTypeFontManager : FontManager {
} }
} }
~this() { ~this() {
Log.d("FreeTypeFontManager ~this() active fonts: ", _activeFonts.length); Log.d("FreeTypeFontManager ~this()");
_activeFonts.clear(); //_activeFonts.clear();
foreach(ref FontFileItem item; _fontFiles) { foreach(ref FontFileItem item; _fontFiles) {
destroy(item); destroy(item);
item = null; item = null;
} }
_fontFiles.length = 0; _fontFiles.length = 0;
Log.d("Destroyed all fonts. Freeing library.");
// uninit library // uninit library
if (_library) if (_library)
FT_Done_FreeType(_library); FT_Done_FreeType(_library);

View File

@ -72,6 +72,11 @@ class ImageCache {
} }
~this() { ~this() {
Log.i("Destroying ImageCache"); Log.i("Destroying ImageCache");
foreach (ref item; _map) {
destroy(item);
item = null;
}
_map.clear();
} }
} }
@ -108,14 +113,17 @@ class DrawableCache {
bool _error; bool _error;
bool _used; bool _used;
DrawableRef _drawable; DrawableRef _drawable;
private int _instanceCount;
this(string id, string filename, bool tiled) { this(string id, string filename, bool tiled) {
_id = id; _id = id;
_filename = filename; _filename = filename;
_tiled = tiled; _tiled = tiled;
_error = filename is null; _error = filename is null;
Log.d("Created DrawableCacheItem, count=", ++_instanceCount);
} }
~this() { ~this() {
_drawable.clear(); _drawable.clear();
Log.d("Destroyed DrawableCacheItem, count=", --_instanceCount);
} }
/// remove from memory, will cause reload on next access /// remove from memory, will cause reload on next access
void compact() { void compact() {
@ -213,6 +221,11 @@ class DrawableCache {
} }
~this() { ~this() {
Log.i("Destroying DrawableCache"); Log.i("Destroying DrawableCache");
foreach (ref item; _idToDrawableMap) {
destroy(item);
item = null;
}
_idToDrawableMap.clear();
} }
} }

View File

@ -472,6 +472,11 @@ class Theme : Style {
~this() { ~this() {
Log.d("Theme destructor"); Log.d("Theme destructor");
foreach(ref Style item; _byId) {
destroy(item);
item = null;
}
_byId.clear();
} }
/// create wrapper style which will have currentTheme.get(id) as parent instead of fixed parent - to modify some base style properties in widget /// create wrapper style which will have currentTheme.get(id) as parent instead of fixed parent - to modify some base style properties in widget
@ -520,6 +525,10 @@ class Theme : Style {
return _byId[id]; return _byId[id];
return this; return this;
} }
void dumpStats() {
Log.d("Theme ", _id, ": children:", _children.length, ", substates:", _substates.length, ", mapsize:", _byId.length);
}
} }
/// to access current theme /// to access current theme
@ -542,6 +551,7 @@ Theme createDefaultTheme() {
button.createState(State.Disabled, State.Disabled).backgroundImageId("btn_default_small_normal_disable"); button.createState(State.Disabled, State.Disabled).backgroundImageId("btn_default_small_normal_disable");
button.createState(State.Pressed, State.Pressed).backgroundImageId("btn_default_small_pressed"); button.createState(State.Pressed, State.Pressed).backgroundImageId("btn_default_small_pressed");
button.createState(State.Focused, State.Focused).backgroundImageId("btn_default_small_selected"); button.createState(State.Focused, State.Focused).backgroundImageId("btn_default_small_selected");
res.dumpStats();
return res; return res;
} }