I'm trying to figure out how to properly destroy a Marionette controller. As I delve into understanding Marionette and Backbone garbage collection, I'm encountering some hurdles...
The controller in question creates multiple views, each potentially with several event listeners bound to them. The structure of the code is like this:
myController.js
---------------
Marionette = require('backbone.marionette');
MyView = require('path/to/myView');
var MyController = Marionette.Controller.extend({
initialize: function(options) {
console.log('init');
}
onDestroy: function() {
console.log('should be destroyed');
}
showData: function() {
console.log('create view');
myView = new MyView();
}
});
appController.js
----------------
MyController = require('path/to/myController');
var controller = new MyController()
controller.showData();
controller.destroy();
output:
//init
//create view
//should be destroyed
Even though the onDestroy method runs, the Controller persists...
I suspect it could be due to event listeners still being attached to the views. Pardon any strange formatting; I've translated this from CoffeeScript.