View Full Version : Form.close() doesn't destroy form itself

3 Dec 2011, 3:23 PM
Hi guys,

Issue: I'm closing form (I didn't define closeAction, hence it's default - 'destroy') but it's not destroyed.

Code for creating/destroying on clicking login/logout buttons:

onLoggedIn: function ()

onLoggedOut: function ()

createTaskList: function ()

if (this.taskList)
console.log('Exception: task list is still alive!');

this.taskList = Ext.widget('taskList');

destroyTaskList: function ()
// this.taskList.destroy(); // I also tried this method, but still doesn't work

When clicking login (create), logout (destroy??) and login again, 'Exception: task list is still alive!' is written to console. I also debugged this.taskList before it's second creation - it still contains positions, names, children, etc.

Am I missing something?

Thanks in advance.

4 Dec 2011, 1:46 PM
Hi guys

Still playing with this. Got the second similar issue with another form. When I close form, reference to it is still defined and contains info that "was actual". However, I'd expect it to be set to "undefined" after closing form. What am I missing?


this.userSearch = Ext.widget('userSearch');
// This line create window (widget). After closing this form (using either "close()" or "X" button) I expect this.userSearch == undefined. Why not so?

4 Dec 2011, 3:42 PM
Destroying a component will remove its elements from the DOM and dismantle some internal state but it won't stop the object existing. Any references to it will continue to exist. Once all references are removed it will be eligible for garbage collection.

So if you do something like this:

var win = Ext.create('Ext.window.Window', {...});


console.log(win); // win still points at the destroyed object

Keep in mind that JavaScript doesn't have any built-in destruction mechanism for objects, destroy() is an ExtJS artefact. You can't delete an object from memory, it happens automatically via garbage collection once all references all removed.

4 Dec 2011, 11:32 PM
Thank you, it's what I was thinking but you made it clear.

And what is "right" way to check whether window is really closed if my reference is still alive?


var win = Ext.create('Ext.window.Window', {...});win.destroy();// How can I know here that "win" is destroyed like "if (win.exists)"? I only see the way to subscribe for "destroy" event but it's kind of workaround
Thank you

4 Dec 2011, 11:47 PM
There are a load of different ways. Difficult to say what's best without the context.

Subscribing to the destroy event isn't necessarily a bad solution.
You could check the isDestroyed property. It isn't documented but it would work.
Hiding the window rather than destroying it is a common solution. From what I've seen of your code this is probably my preferred approach.
Another option is to use a component query to check if the window still exists rather than relying on a reference stored on this. A destroyed window won't come back in a component query.

4 Dec 2011, 11:59 PM
Much thanks! Now I have what to choose from :)