{"action":"created","issue":{"url":"https://api.github.com/repos/openfl/openfl/issues/1274","repository_url":"https://api.github.com/repos/openfl/openfl","labels_url":"https://api.github.com/repos/openfl/openfl/issues/1274/labels{/name}","comments_url":"https://api.github.com/repos/openfl/openfl/issues/1274/comments","events_url":"https://api.github.com/repos/openfl/openfl/issues/1274/events","html_url":"https://github.com/openfl/openfl/issues/1274","id":178431943,"number":1274,"title":"Stage can retain references in __stack","user":{"login":"Leander1P","id":9867798,"avatar_url":"https://avatars.githubusercontent.com/u/9867798?v=3","gravatar_id":"","url":"https://api.github.com/users/Leander1P","html_url":"https://github.com/Leander1P","followers_url":"https://api.github.com/users/Leander1P/followers","following_url":"https://api.github.com/users/Leander1P/following{/other_user}","gists_url":"https://api.github.com/users/Leander1P/gists{/gist_id}","starred_url":"https://api.github.com/users/Leander1P/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Leander1P/subscriptions","organizations_url":"https://api.github.com/users/Leander1P/orgs","repos_url":"https://api.github.com/users/Leander1P/repos","events_url":"https://api.github.com/users/Leander1P/events{/privacy}","received_events_url":"https://api.github.com/users/Leander1P/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-09-21T18:51:42Z","updated_at":"2016-09-22T16:44:35Z","closed_at":"2016-09-21T21:24:21Z","body":"If you do `stage.focus = null` somewhere (e.g. in `DisplayObject.__setStageReference( null )` as a result of removing from stage), `Stage.set_focus` will retain a reference to the interactive objects in `__stack`, causing these objects to \"leak\" until next `stage.focus = somethingElse`.\r\n\r\nWe're seeing this keep `TextField`s alive, along with all their parents, even if the link to stage is broken high up (e.g. a `DisplayObjectContainer` well up the parent/child tree).\r\n\r\nLocally, we have a patch that drops the `Stage.__stack` member variable and uses local `var __stack`, and this fixes the issue.\r\n\r\nDoes this seem reasonable?  As far as I can tell, the call sequence shouldn't change even with re-entrant calls to `set_focus` (which should possibly be another issue, since the sequence is a bit wonky if you change focus within e.g. `FOCUS_IN` or `FOCUS_OUT`, but that's a much more elaborate change).  Also, this shouldn't increase number of allocs at all (just how soon the last set is available for GC).\r\n\r\n(Can submit a PR with this elsewhere over the next week, but figured an issue and general request for comments would be a good start.)\r\n\r\n```\r\nIndex: Stage.hx\r\n===================================================================\r\n--- Stage.hx\t(revision 1153)\r\n+++ Stage.hx\t(revision 1154)\r\n@@ -115,7 +115,6 @@\r\n \tprivate var __mouseY:Float;\r\n \tprivate var __renderer:AbstractRenderer;\r\n \tprivate var __rendering:Bool;\r\n-\tprivate var __stack:Array<DisplayObject>;\r\n \tprivate var __transparent:Bool;\r\n \tprivate var __wasDirty:Bool;\r\n \t\r\n@@ -176,7 +175,6 @@\r\n \t\t#end\r\n \t\t\r\n \t\t__clearBeforeRender = true;\r\n-\t\t__stack = [];\r\n \t\t__mouseOutStack = [];\r\n \t\t\r\n \t\tstage3Ds = new Vector ();\r\n@@ -1471,7 +1469,7 @@\r\n \t\t\tif (oldFocus != null) {\r\n \t\t\t\t\r\n \t\t\t\tvar event = new FocusEvent (FocusEvent.FOCUS_OUT, true, false, __focus, false, 0);\r\n-\t\t\t\t__stack = [];\r\n+\t\t\t\tvar __stack = [];\r\n \t\t\t\toldFocus.__getInteractive (__stack);\r\n \t\t\t\t__stack.reverse ();\r\n \t\t\t\t__fireEvent (event, __stack);\r\n@@ -1481,7 +1479,7 @@\r\n \t\t\tif (__focus != null) {\r\n \t\t\t\t\r\n \t\t\t\tvar event = new FocusEvent (FocusEvent.FOCUS_IN, true, false, oldFocus, false, 0);\r\n-\t\t\t\t__stack = [];\r\n+\t\t\t\tvar __stack = [];\r\n \t\t\t\tvalue.__getInteractive (__stack);\r\n \t\t\t\t__stack.reverse ();\r\n \t\t\t\t__fireEvent (event, __stack);\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/openfl/openfl/issues/comments/248959889","html_url":"https://github.com/openfl/openfl/issues/1274#issuecomment-248959889","issue_url":"https://api.github.com/repos/openfl/openfl/issues/1274","id":248959889,"user":{"login":"Leander1P","id":9867798,"avatar_url":"https://avatars.githubusercontent.com/u/9867798?v=3","gravatar_id":"","url":"https://api.github.com/users/Leander1P","html_url":"https://github.com/Leander1P","followers_url":"https://api.github.com/users/Leander1P/followers","following_url":"https://api.github.com/users/Leander1P/following{/other_user}","gists_url":"https://api.github.com/users/Leander1P/gists{/gist_id}","starred_url":"https://api.github.com/users/Leander1P/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Leander1P/subscriptions","organizations_url":"https://api.github.com/users/Leander1P/orgs","repos_url":"https://api.github.com/users/Leander1P/repos","events_url":"https://api.github.com/users/Leander1P/events{/privacy}","received_events_url":"https://api.github.com/users/Leander1P/received_events","type":"User","site_admin":false},"created_at":"2016-09-22T16:44:35Z","updated_at":"2016-09-22T16:44:35Z","body":"That sounds like a very sane approach.  =)  Can write up a new issue if it shows up as hot at any point in the future.\r\n\r\nThanks!"}}
{"actor":{"display_login":"Leander1P"}}