Hi Trevor, Dirk,
I never found a definitive way to properly release from memory a complex window. As Dirk said $.gc() may help, but depending on the version of ScriptUI some precautions are necessary to prevent ID from crashing. What is sure is that you need to carefully nullify references, remove some event listeners at the right time, deal with closures if used, and so on. But even with much effort there are still tricky memory leaks, for example with ScriptUIBrush objects—not to mention very obscure issues when dealing with win.layout object.
Anyway, when you have a palette in a persistent engine (and provided that you want it to behave as a singleton), I don't see the reason why you want to actually kill the reference in memory. Just set and manage that instance in a compact location, and make sure you never needlessly rebuild your stuff.
What is the problem with the following code?
#targetengine ManageSingletonPalette
$.UserInterface || ($.UserInterface = function F(/*-1=destroy 0=restore 1=rebuild*/FLAG)//--------------------------------------{ F.W || (F.W=Window.find("palette", "My Palette")); // Destroy? // --- if( F.W && FLAG ) { F.W.visible && F.W.close(); F.W = null; delete F.W; } if( -1===FLAG ) return; // Create? // --- if( !F.W ) { F.W = new Window('palette', "My Palette", [50,50,300,300], {resizeable:true}); F.W.add('edittext',[50,50,200,200]); // etc. } F.W.visible || F.W.show();});
$.UserInterface(); // use -1 to KILL the palette, 1 to REBUILD it from scratch
@+
Marc