Looks like we cannot reproduce this. Please provide another test case to reproduce this issue.
  1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    28
    Vote Rating
    2
    ratmat2000 is on a distinguished road

      0  

    Default 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.

    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);
    	},
    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.

    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;
    },

  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    18
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    Thank you for the report.

    Sencha Inc

    Jamie Avins

    @jamieavins

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    28
    Vote Rating
    2
    ratmat2000 is on a distinguished road

      0  

    Default


    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.

  4. #4
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    18
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    Thank you for the clarification.

    Sencha Inc

    Jamie Avins

    @jamieavins

Thread Participants: 1