{ "id": "155131", "key": "ALOY-1361", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [ { "id": "17974", "name": "alloy 1.8.0", "archived": false, "released": true, "releaseDate": "2016-03-16" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2016-03-24T00:41:09.000+0000", "created": "2016-02-25T14:50:54.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "alloy", "databinding", "destroy" ], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-03-06T18:50:03.000+0000", "status": { "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.", "name": "Resolved", "id": "5", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "12326", "name": "XML", "description": "View XML and parsing" } ], "description": "If you have an Alloy component that uses databinding and has conditional code defined in the xml, the destroy function is not taking into consideration the fact that the component may be undefined before calling the `off` function.\r\n\r\nAlloy xml: \r\n\r\n{code:xml}\r\n\t \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n{code}\r\n\r\nGenerated code: \r\n\r\n{code:javascript}\r\n if ($.args.editmode) {\r\n\r\n // ------ only showing relevant code ------\r\n\r\n var __alloyId287 = Alloy.Collections[\"trainer\"] || trainer;\r\n __alloyId287.on(\"fetch destroy change add remove reset\", __alloyId288);\r\n\r\n\r\n }\r\n\r\n exports.destroy = function() {\r\n __alloyId281.off(\"fetch destroy change add remove reset\", __alloyId282);\r\n __alloyId293.off(\"fetch destroy change add remove reset\", __alloyId294);\r\n __alloyId314.off(\"fetch destroy change add remove reset\", __alloyId315);\r\n __alloyId330.off(\"fetch destroy change add remove reset\", __alloyId331);\r\n\tAlloy.Models.mymodel.off(\"fetch change destroy\", __alloyId346);\r\n };\r\n\r\n{code}\r\n\r\nIn this case, `__alloyId281` is actually undefined because it was declared and a value assigned inside the conditional if block. \r\n\r\nThis is a pretty serious issue as I believe the error that occurs is stopping the other (existing) `off` functions from being called and causing a memory leak.\r\n ", "attachment": [], "flagged": false, "summary": "Destroy calling off on variables that may be undefined", "creator": { "name": "brentonhouse", "key": "brentonhouse", "displayName": "Brenton House", "active": true, "timeZone": "America/Chicago" }, "subtasks": [], "reporter": { "name": "brentonhouse", "key": "brentonhouse", "displayName": "Brenton House", "active": true, "timeZone": "America/Chicago" }, "environment": null, "closedSprints": [ { "id": 615, "state": "closed", "name": "2016 Sprint 07 Tooling", "startDate": "2016-03-26T00:40:48.770Z", "endDate": "2016-04-09T00:40:00.000Z", "completeDate": "2016-04-11T04:48:57.781Z", "originBoardId": 121 } ], "comment": { "comments": [ { "id": "377888", "author": { "name": "brentonhouse", "key": "brentonhouse", "displayName": "Brenton House", "active": true, "timeZone": "America/Chicago" }, "body": "Added PR: https://github.com/appcelerator/alloy/pull/762\r\n", "updateAuthor": { "name": "brentonhouse", "key": "brentonhouse", "displayName": "Brenton House", "active": true, "timeZone": "America/Chicago" }, "created": "2016-02-25T16:23:53.000+0000", "updated": "2016-02-25T16:23:53.000+0000" }, { "id": "377892", "author": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "body": "This is a valid PR. Thanks for letting us know. Our engineer will look into it. ", "updateAuthor": { "name": "sdarda", "key": "sdarda", "displayName": "Sharif AbuDarda", "active": false, "timeZone": "Asia/Dhaka" }, "created": "2016-02-25T16:56:32.000+0000", "updated": "2016-02-25T16:56:32.000+0000" }, { "id": "380560", "author": { "name": "fmiao", "key": "fmiao", "displayName": "Feon Sua Xin Miao", "active": true, "timeZone": "America/Vancouver" }, "body": "PR merged.", "updateAuthor": { "name": "fmiao", "key": "fmiao", "displayName": "Feon Sua Xin Miao", "active": true, "timeZone": "America/Vancouver" }, "created": "2016-03-24T00:41:09.000+0000", "updated": "2016-03-24T00:41:09.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }