ソースを参照

fixed memory leaks in view system

Nicolas Cannasse 3 年 前
コミット
143712e51b
3 ファイル変更14 行追加3 行削除
  1. 7 2
      hide/comp/Scene.hx
  2. 5 1
      hide/ui/View.hx
  3. 2 0
      libs/golden/ContentItem.hx

+ 7 - 2
hide/comp/Scene.hx

@@ -45,10 +45,16 @@ class Scene extends Component implements h3d.IDrawable {
 		for( c in cleanup )
 			c();
 		cleanup = [];
+		ide.unregisterUpdate(sync);
+		@:privateAccess s2d.window.removeResizeEvent(s2d.checkResize);
 		engine.dispose();
 		@:privateAccess engine.driver = null;
 		untyped canvas.__scene = null;
 		canvas = null;
+		if( h3d.Engine.getCurrent() == engine ) @:privateAccess h3d.Engine.CURRENT = null;
+		untyped js.Browser.window.$_ = null; // jquery can sometimes leak s2d
+		@:privateAccess haxe.NativeStackTrace.lastError = null; // possible leak there
+		window.dispose();
 	}
 
 	public function addListener(f) {
@@ -138,8 +144,7 @@ class Scene extends Component implements h3d.IDrawable {
 
 	function sync() {
 		if( new Element(canvas).parents("html").length == 0 ) {
-			window.dispose();
-			ide.unregisterUpdate(sync);
+			dispose();
 			return;
 		}
 		if( !visible || pendingCount > 0)

+ 5 - 1
hide/ui/View.hx

@@ -13,6 +13,7 @@ typedef ViewOptions = { ?position : DisplayPosition, ?width : Int }
 class View<T> extends hide.comp.Component {
 
 	var container : golden.Container;
+	var containerView : golden.ContentItem;
 	var watches : Array<{ keep : Bool, path : String, callb : Void -> Void }> = [];
 	public var fullScreen(get,set) : Bool;
 	public var keys(get,null) : Keys;
@@ -159,7 +160,9 @@ class View<T> extends hide.comp.Component {
 			});
 		});
 
-		untyped cont.parent.__view = this;
+		if( containerView != null ) containerView.__view = null;
+		containerView = container.parent;
+		containerView.__view = this;
 		element = cont.getElement();
 	}
 
@@ -244,6 +247,7 @@ class View<T> extends hide.comp.Component {
 				s.dispose();
 		}
 		element = null;
+		containerView.__view = null;
 	}
 
 	function buildTabMenu() : Array<hide.comp.ContextMenu.ContextMenuItem> {

+ 2 - 0
libs/golden/ContentItem.hx

@@ -10,6 +10,8 @@ extern class ContentItem {
 	var config : Config.ItemConfig;
 	var header : Header;
 
+	var __view : Dynamic;
+
 	public function addChild( config : Config.ItemConfig, ?index : Int ) : Void;
 	public function on( type : String, callb : Event<ContentItem> -> Void ) : Void;
 	public function off( type : String ) : Void;