-
25 Jan 2012 12:02 AM #1
destroy event not fired when component removed from viewport
destroy event not fired when component removed from viewport
It seems that the destroy event is not being fired when components are removed from the viewport. This results in the component remaining in the viewports reference cache and likely not getting garbage collected. The component is getting removed from the DOM because the destroy method is being called on the component.
Here is the code I'm using to create the component. I was expecting that each time the component was destroyed (or had not been created), that the getLoginView() method would return null.
I have verified that the destroy method of the loginView component is being called but the reference cache in the viewport still contains a reference to the loginView.Code:showLoginView: function() { var view; if (!(view = this.getLoginView())) { view = Ext.create('HealthVille.view.LoginView'); this.getViewport().add(view); console.log('Created ' + Ext.getDisplayName(view)); } else { view.show(); } }, Here is the code to destroy the loginView component: destroyLoginView: function() { var view; if (view = this.getLoginView()) { var viewport = this.getViewport(); viewport.remove(view); },
Here is the code that is supposed to remove the component from the reference cache but the destroy event is never fired. me.refCache[ref] = null is never called.
getRef: function(ref, info, config) {
this.refCache = this.refCache || {};
info = info || {};
config = config || {};
Ext.apply(info, config);
if (info.forceCreate) {
return Ext.ComponentManager.create(info, 'component');
}
var me = this,
cached = me.refCache[ref];
if (!cached) {
me.refCache[ref] = cached = Ext.ComponentQuery.query(info.selector)[0];
if (!cached && info.autoCreate) {
me.refCache[ref] = cached = Ext.ComponentManager.create(info, 'component');
}
if (cached) {
cached.on('destroy', function() {
me.refCache[ref] = null;
});
}
}
return cached;
},
-
25 Jan 2012 9:20 AM #2Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,651
- Vote Rating
- 14
Thank you for the report.
-
25 Jan 2012 9:43 AM #3
I figured out the problem here. I had custom destroy methods on my view that were not calling this.callParent(). Adding those calls back into my destroy methods fixed the problem.
-
25 Jan 2012 9:49 AM #4Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,651
- Vote Rating
- 14
Thank you for the clarification.
Looks like we cannot reproduce this. Please provide another test case to reproduce this issue.


Reply With Quote