View Full Version : Bizarre object leak / multi-saves on Cancel

14 Aug 2009, 8:00 PM
I'm experiencing a really strange issue, which seems like an object leak and/or transparent reuse of multiple objects... there's probably too much code to post, so I'll just try to describe the environment adequately.

I have an Ext.Window object that gets created using "new" operator. The window contains a set of tabs, each of which contain a different wizard per tab (modified Ext.us.wizard objects, which are derived from FormPanels as wizard "card" forms).

Everything works as expected the first time through - user-entered data gets collected, then written to the server and stored just fine. Then, the user presses the "Cancel" button (for example) to abort the wizard. This is expected to cause the Window to close...

In order to deal with the user's request to bail out of the wizard, I have trapped the wizard-level (lower-level) onClose events and bubble them up several layers in order to call the Window.destroy() function on the containing Ext.Window object so the window closes - expecting destroy() would cause a cascade of object cleanup back down the component hierarchy... like so:

This is the "bubbling up" of the close events...

(from within the lower-level wizard tabs)
onCancelClick: function() { this.ownerCt.onWizardCancel(); },

(which calls the higher-level the tabpanel object)

onWizardCancel:function() {
var parent = this.ownerCt;
parent.ownerCt.destroy(); // close the containing window object

function projectWizard(){
if( mainWin != null ) // there was a previous instance
mainWin.destroy(); // this is redundant, as destroy() has been called above as well
delete mainWin;
mainWin = null;

(where the main wizard window gets created/re-created)
if( mainWin == null ) {
mainWin = new Ext.Window({
id: 'wizard-app',
... (rest of main wizard window)

Then, the wizard is activated by the user a 2nd time. New values are entered, and then saved to the server once again. The newly-entered values get saved just fine; however, the prior wizard instance values are also being saved somehow!
(I can delete them and they all come back - if I don't delete them before running the wizard again, then I get a duplicate record error since they already exist on the server).

So, clearly there's "remnants" of the prior wizard "card" (form) instances that are still hanging around. I've even placed explicit window destory() and object delete operators ahead of creating a new window to ensure the window has been destroyed; however, it seems there's multiple objects responding to the Finish button event! Clearly, multiple instances of the wizard (or more likely it's FormPanel objects) are being activated, even though I only see the most recent one breakpoint in Firebug.

Very bizarre. I'm not sure how to isolate this issue or if I need to be doing explicit close event interception and object cleanup/deletion at every level of nested ExtJS objects (doesn't seem so based on everything I've read).

Admittedly, bubbling the onClose() events up when the user presses "Cancel" seems a bit odd, but was only way I know of to actually process the Close button up through all the various levels of the component hierarchy. Am I somehow by-passing proper cleanup?

Any ideas? Open to suggestions and better ways to handle this.



15 Aug 2009, 5:07 AM
The terms "Window" and "works first time though" ring alarm bells.


15 Aug 2009, 8:57 AM
Turns out the issue wasn't an object leak after all...

I was doing an "insert(0, rec)" into the datastore each time, and not clearing the prior data before each create request to the server.


Sorry. I should've look more carefully at the post request/response in Firebug, which is what caused me to realize where the real issue was.

Thanks for the response Animal.