[ALOY-432] add destroy() function to all controllers
| GitHub Issue | n/a |
|---|---|
| Type | Improvement |
| Priority | High |
| Status | Resolved |
| Resolution | Fixed |
| Resolution Date | 2012-12-19T04:12:01.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Alloy 0.3.4, 2012 Sprint 26 |
| Components | Runtime |
| Labels | notable |
| Reporter | Tony Lukasavage |
| Assignee | Unknown |
| Created | 2012-12-19T03:14:26.000+0000 |
| Updated | 2018-03-07T22:25:47.000+0000 |
Description
*IMPORTANT*: Calling destroy() will be critical for preventing memory leaks in alloy code that employs model-view binding.
We will be adding a *destroy()* function to all controllers. Under the hood this will be added as:
exports.destroy = function() {
// auto-generated destroy code
}
In its initial form, the destroy() function will be used only to remove event listeners tied to global and local references to models/collections, which are created when model-view binding is employed. A typical example of using it would be when you close a controller's window if it or any of its UI components used model-view binding.
$.win.on('close', function() {
$.destroy(); // clean up binding
});
This will prevent any possible memory leaks, specifically when making bindings against a global model (Alloy.Models) or collection (Alloy.Collections).
All model and collection binding can now be cleaned, and made free of potential memory leaks, by calling destroy() on the controller.