Skip to main content
Alan_AEDScripts
Inspiring
January 4, 2014
Question

Killing windows (palettes)

  • January 4, 2014
  • 2 replies
  • 2124 views

Hi there,

Trying to figure out how to kill off a palette (entirely from memory).

Running the code below - first alert is null, the window object does not exist.

When it's run a second time it alerts [object] as the palette remains in memory etc.

So the close() method seems to just hide a palette, how to kill it completely?

What is the difference between .close() and .hide()  is essentially my question?

Thanks.!

Alan.

//=======================================================

var wName = "tester"

alert(Window.find(wName ))

var w = new Window("palette", wName , undefined, {name: wName });

w.preferredSize=[250,250];

 

var c = w.add("button",undefined,"kill window.");

c.onClick=function(){this.parent.close();}

w.show();

//=======================================================

This topic has been closed for replies.

2 replies

Inspiring
January 9, 2014

excerpt from the pdf page 69 on  http://www.kahrel.plus.com/indesign/scriptui.html

a palette is always created in a persistent engine. Now, when a script that runs in a persistent engine finishes, any variables created by the script remain in memory. The same goes for palettes: even if you close a palette using close(), the palette remains in memory.You should therefore always check if a particular palette exists before you create it, along the following lines:

function createMessageWindow (){

   var w = Window.find ("palette", "Message");

   if (w == null){

      w = new Window ("palette", "Message");

      w.mess = w.add ("statictext", [0,0,300,20], "");

    }

    w.show();

}

Legend
January 9, 2014

excerpt from the pdf page 69 on  http://www.kahrel.plus.com/indesign/scriptui.html

Nice find. I still find that a bit dangerous, given that the test I did earlier for Alan showed the window reappear, but none of it functionality existed. Maybe the "reviving" method needs to be handled differently, but this instantly makes me wonder if you check for the window and said window existed, but needed to have functionality reassigned to it, that could be very bad. Again maybe the window needs to be brought back some other way than using show(); Just my 2 cents.

Alan_AEDScripts
Inspiring
January 10, 2014

What I am doing (in my own scripts ) as suggested by Peter Kahrel is looking for the windows in memory and stripping and refreshing them. I am using .hide() and .show() once they are created instead of close()

//=======================================================

var wName = "tester"

var w = new Window("palette", wName , undefined, {name: wName });

w.preferredSize=[250,250];

var c = w.add("button",undefined,"kill window.");

//c.onClick=function(){this.parent.close();}

w.show();

$.sleep(2000);

w.close();

w = null ; // w being global.

alert(Window.find(wName ))

//=======================================================

Legend
January 7, 2014

So the close() method seems to just hide a palette, how to kill it completely?

Actually it seems to kill only part of it. If you show() your Window object instead of alert()...

var wName = "tester"

Window.find(wName ).show()     //Show the previous window

var w = new Window("palette", wName , undefined, {name: wName });

w.preferredSize=[250,250];

var c = w.add("button",undefined,"kill window.");

c.onClick=function(){this.parent.close();}

w.show();

It will make the old window visible, but the button no longer has the onClick functionality. It's just a UI shell. Not sure why the window object hangs around after closing, the old window instance is not clearing until the app closes. Maybe Window objects remain until a session ends (app quits).

Alan_AEDScripts
Inspiring
January 7, 2014

Thanks David, seems to be the case - I guess it's a case of looking for the same window in memory when re-running a script.    

UQg
Legend
January 9, 2014

Hi Alan, thanks for raising this topic!!

I don't know too what is the difference between .close() and .hide() and this is really puzzling me.

May someone who knows answer this !!!!

From my "experience", close does not destroy the window object as one would expect (unless it is a dialog type window).

Palettes still live after .close() and non dockable ones can be shown again.

With simple code like var c = w.add("button",undefined,"kill window."); c.onClick=function(){this.parent.close();}

you can't expect your button to be an actual window killer, but what to do instead is a mystery.

I'm not sure, but i think you must explicitely say that the window object is no longer a window object, like set w=null;

But for instance c.onClick=function(){this.parent.close(); this.parent=null;}; has no chance to work either since the window can't be nullified while one of its child is referencing it...

However c.onClick=function(){w.close(); w=null;}; may work if the window is simple enough.. Can't tell you why.

Destroying a worskpace  (ready for garbage) with some UI stuff inside, which may have plenty of self-references and sub-workspaces, is hard and it would be nice if there were a topic on this in the Tool Guide.

A while back i was trying to make a script with a keyboard (256 buttons). After launching/closing the script "several" times (debug) i eventually got a system error : can't create more buttons

There were still all alive (around 8000).

Xavier.