[ALOY-1361] Destroy calling off on variables that may be undefined
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Resolved |
Resolution | Fixed |
Resolution Date | 2016-03-24T00:41:09.000+0000 |
Affected Version/s | n/a |
Fix Version/s | alloy 1.8.0 |
Components | XML |
Labels | alloy, databinding, destroy |
Reporter | Brenton House |
Assignee | Unknown |
Created | 2016-02-25T14:50:54.000+0000 |
Updated | 2018-03-06T18:50:03.000+0000 |
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.
Alloy xml:
<TableViewRow id="trainer_row" layout="composite" class="listitem_row" hasChild="true" onClick="$.togglePicker" if="$.args.editmode">
<View height="50" top="0" layout="composite" touchEnabled="false">
<Label text="Trainer" class="listitem_settings_name" touchEnabled="false" />
<Label text="{mymodel.trainer_name}" class="listitem_settings_value_haschild" touchEnabled="false" />
</View>
<Picker id="trainer" width="350" height="150" visible="false" onChange="$.onChange" top="40">
<Column dataCollection="trainer">
<Row title="{name}" value="{id}" />
</Column>
</Picker>
</TableViewRow>
Generated code:
if ($.args.editmode) {
// ------ only showing relevant code ------
var __alloyId287 = Alloy.Collections["trainer"] || trainer;
__alloyId287.on("fetch destroy change add remove reset", __alloyId288);
}
exports.destroy = function() {
__alloyId281.off("fetch destroy change add remove reset", __alloyId282);
__alloyId293.off("fetch destroy change add remove reset", __alloyId294);
__alloyId314.off("fetch destroy change add remove reset", __alloyId315);
__alloyId330.off("fetch destroy change add remove reset", __alloyId331);
Alloy.Models.mymodel.off("fetch change destroy", __alloyId346);
};
In this case, __alloyId281
is actually undefined because it was declared and a value assigned inside the conditional if block.
This 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.
Added PR: https://github.com/appcelerator/alloy/pull/762
This is a valid PR. Thanks for letting us know. Our engineer will look into it.
PR merged.