PDA

View Full Version : [SOLVED] It seems the (Ext.Window)object didn't destroyed on close.event



tatsu
11 Aug 2009, 10:12 AM
I would like to create an ext-application with a great number of windows. When i destroy an object based on the Ext.Window-class, it seems exist beyond.

My Questions are:
Is that the common behaviour of an ext- / javascript-application?
What's the optimum method to handle Ext-Objects like Ext.Window?

Example:

Ext.onReady(function(){
mainWindow = new Ext.Window({ // Create object
id: 'samplewindow',
title: 'Samplewindow',
layout:'fit',
width: 250,
height: 100,
});

mainWindow.show();
console.log(mainWindow); // Firebug-logging
alert('Destroy window');
mainWindow.close();
// Firebug-logging (It seems the Object didn't destroyed)
console.log(mainWindow);
mainWindow = null; // Object still exists?
});Thanks in advance.

jay@moduscreate.com
11 Aug 2009, 10:18 AM
items can't set themselves to null.

Condor
11 Aug 2009, 10:24 AM
Javascript is referenced based, so as long as you hold a reference to it the object will exist.

Setting the last reference to null (like you do on the last line) will mark the object for deletion, but you still have to wait for the garbage collection to pick up on that.

jay@moduscreate.com
11 Aug 2009, 10:34 AM
in addition to condor's comment, you can delete a reference by using the delete keyword.

tatsu
11 Aug 2009, 11:03 AM
Hello Jay, hello Condor.

I thank you for the answers. I'm an Ext JS newbie and would make sure that I have understand you correctly.

Speculations:
The close event from the Ext.Window instance destroys all his child components but not itself.
Setting the last reference to null will mark the object for deletion.But if I allocate a new object to the same variable "mainWindow" the old object reference in firebug still works. It that normal?

Example:

Ext.onReady(function(){
// Create a object with reference named 'mainWindow'
mainWindow = new Ext.Window({
id: 'samplewindow',
title: 'Samplewindow',
layout:'fit',
width: 250,
height: 100,
});

mainWindow.show();
mainWindow.close();

// Firebug-logging (It seems the Object didn't destroyed)
console.log(mainWindow);
delete(mainWindow);

// Create new object with same reference named 'mainWindow'
mainWindow = new Ext.Window({
id: 'samplewindow2',
title: 'Samplewindow2',
layout:'fit',
width: 250,
height: 100,
});
// Firebug-logging (the new object)
console.log(mainWindow);
// At this point the old and the new object are accessible in firebug
});

Thanks in advance.

jay@moduscreate.com
11 Aug 2009, 11:22 AM
ok, first you wan to locally scope mainWindow by using the var keyword.

var mainWindow = new Ext.Window({});.

This is not an ExtJS thing, but a javascript one. In fact, all of the symantics that we're discussing are basic JavaScript.

That said, delete actually deletes the local reference. Remember that you're inspecting a reference to the instance of Ext.Window. From a high level, when an Ext JS component is "Destroyed", its dom nodes are removed, listeners purged and it is deregistered from the component manager. The JavaScript object is not nullified (or destroyed as you call it).

(from my understanding)
If you're going to overwrite the reference for mainWindow, there is no reason set it as null before hand or even delete the reference. Simply overwriting it will 'unlink' the reference from the object in memory, thus the original object that was being referenced will be picked up by the garbage collector.


Does this help.

tatsu
11 Aug 2009, 11:40 AM
Hello Jay,
thank you again for helping me. My questions are answered :-)

Condor
11 Aug 2009, 9:56 PM
And one final note:
As I said, the window will only be destroyed after the final reference is deleted. In your case, Firebug still had a reference to the old object.