{"action":"created","issue":{"url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/2015","repository_url":"https://api.github.com/repos/HaxeFlixel/flixel","labels_url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/2015/labels{/name}","comments_url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/2015/comments","events_url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/2015/events","html_url":"https://github.com/HaxeFlixel/flixel/issues/2015","id":197435649,"number":2015,"title":"FlxBar Memory Leak","user":{"login":"GoKidGames","id":19740386,"avatar_url":"https://avatars.githubusercontent.com/u/19740386?v=3","gravatar_id":"","url":"https://api.github.com/users/GoKidGames","html_url":"https://github.com/GoKidGames","followers_url":"https://api.github.com/users/GoKidGames/followers","following_url":"https://api.github.com/users/GoKidGames/following{/other_user}","gists_url":"https://api.github.com/users/GoKidGames/gists{/gist_id}","starred_url":"https://api.github.com/users/GoKidGames/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoKidGames/subscriptions","organizations_url":"https://api.github.com/users/GoKidGames/orgs","repos_url":"https://api.github.com/users/GoKidGames/repos","events_url":"https://api.github.com/users/GoKidGames/events{/privacy}","received_events_url":"https://api.github.com/users/GoKidGames/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-23T23:06:28Z","updated_at":"2016-12-24T14:11:13Z","closed_at":"2016-12-24T11:02:48Z","body":"- **Flixel version:** 4.2.0\r\n- **OpenFL version:** 3.6.1\r\n- **Lime version:** 2.9.1\r\n- **Affected targets:** Flash (at least)\r\n\r\n________________________________\r\n\r\n**Code snippet reproducing the issue**:\r\n\r\n```haxe\r\npackage;\r\n\r\nimport flixel.FlxG;\r\nimport flixel.FlxSprite;\r\nimport flixel.FlxState;\r\nimport flixel.ui.FlxBar;\r\nimport flixel.ui.FlxButton;\r\n\r\nclass PlayState extends FlxState\r\n{\r\n    private var _flxBars:Array<FlxBar>;\r\n    private var _parentRefs:Array<FlxSprite>;\r\n    private var _toggleManualButton:FlxButton;\r\n    private var _barCount:Int;\r\n    \r\n    override public function create():Void\r\n    {\r\n        FlxG.debugger.visible = true;\r\n        \r\n        var cols:Int = 8;\r\n        var rows:Int = 6;\r\n        var spacing:Int = 4;\r\n        var barHeight:Int = 6;\r\n        var spriteSize:Int = 32;\r\n        var buttonHeight:Int = 30;\r\n        var buttonWidth:Int = 80;\r\n        var startX:Float = (FlxG.width - ((spriteSize + spacing) * cols)) / 2;\r\n        var startY:Float = (FlxG.height - ((spriteSize + spacing) * rows) + (buttonHeight + spacing)) / 2;\r\n        var x:Float = 0;\r\n        var y:Float = 0;\r\n        var count:Int = 0;\r\n        \r\n        var randomizeButton = new FlxButton(startX + buttonWidth + spacing, startY - (buttonHeight + spacing), \"Randomize\", randomizeHealth);\r\n        _toggleManualButton = new FlxButton(startX, startY - (buttonHeight + spacing), \"ParentRef\", toggleManual);\r\n        \r\n        _barCount = cols * rows;\r\n        \r\n        _parentRefs = new Array();\r\n        _flxBars = new Array();\r\n        \r\n        for (i in 0...cols)\r\n        {\r\n            for (j in 0...rows)\r\n            {\r\n                x = startX + (i * (spriteSize + spacing));\r\n                y = startY + (j * (spriteSize + spacing));\r\n                \r\n                _parentRefs[count] = new FlxSprite(x, y).makeGraphic(spriteSize, spriteSize, 0xFF666666);\r\n                _flxBars[count] = new FlxBar(x, y, null, spriteSize, barHeight, _parentRefs[count], \"health\");\r\n                \r\n                add(_parentRefs[count]);\r\n                add(_flxBars[count]);\r\n                \r\n                count++;\r\n            }\r\n        }\r\n        \r\n        randomizeHealth();\r\n        \r\n        add(randomizeButton);\r\n        add(_toggleManualButton);\r\n        \r\n        super.create();\r\n    }\r\n    \r\n    override public function update(elapsed:Float):Void\r\n    {\r\n        if (_toggleManualButton.text == \"Manual\")\r\n        {\r\n            for (i in 0..._barCount)\r\n                if (_flxBars[i].value != _parentRefs[i].health)\r\n                    _flxBars[i].value = _parentRefs[i].health;\r\n        }\r\n        \r\n        super.update(elapsed);\r\n    }\r\n    \r\n    private function randomizeHealth():Void\r\n    {\r\n        for (i in 0..._barCount)\r\n            _parentRefs[i].health = Math.random() * 100;\r\n    }\r\n    \r\n    private function toggleManual():Void\r\n    {\r\n        if (_toggleManualButton.text == \"Manual\")\r\n        {\t\r\n            for (i in 0..._barCount)\r\n                _flxBars[i].setParent(_parentRefs[i], \"health\");\r\n            \r\n            _toggleManualButton.text = \"ParentRef\";\r\n        }\r\n        else\r\n        {\r\n            for (i in 0..._barCount)\r\n                _flxBars[i].setParent(null, \"\");\r\n            \r\n            _toggleManualButton.text = \"Manual\";\r\n        }\r\n    }\r\n}\r\n```\r\n________________________________\r\n\r\n**Observed behavior:** Memory leak\r\n**Expected behavior:** No memory leak :)\r\n\r\nWhen using parentRef/variable there's a memory leak. When setting the parentRef to null, and update the value manually, the leak stops."},"comment":{"url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/comments/269085825","html_url":"https://github.com/HaxeFlixel/flixel/issues/2015#issuecomment-269085825","issue_url":"https://api.github.com/repos/HaxeFlixel/flixel/issues/2015","id":269085825,"user":{"login":"GoKidGames","id":19740386,"avatar_url":"https://avatars.githubusercontent.com/u/19740386?v=3","gravatar_id":"","url":"https://api.github.com/users/GoKidGames","html_url":"https://github.com/GoKidGames","followers_url":"https://api.github.com/users/GoKidGames/followers","following_url":"https://api.github.com/users/GoKidGames/following{/other_user}","gists_url":"https://api.github.com/users/GoKidGames/gists{/gist_id}","starred_url":"https://api.github.com/users/GoKidGames/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoKidGames/subscriptions","organizations_url":"https://api.github.com/users/GoKidGames/orgs","repos_url":"https://api.github.com/users/GoKidGames/repos","events_url":"https://api.github.com/users/GoKidGames/events{/privacy}","received_events_url":"https://api.github.com/users/GoKidGames/received_events","type":"User","site_admin":false},"created_at":"2016-12-24T14:11:13Z","updated_at":"2016-12-24T14:11:13Z","body":"Thanks for the clarification on what a memory leak really is, Gama11. I guess I'll update them manually for now since it's easy enough to do for my application. I'm using FlxBar in my SaveSlot class, so there are many in use at once. It just bothers me to see that memory graph climb so rapidly :P "}}
{"actor":{"display_login":"GoKidGames"}}