Difference between destroyStack and destroyWindow

Ken Ray kray at sonsothunder.com
Sat Aug 13 12:44:26 EDT 2011

> This property controls whether or not the window owned by a stack is freed when the stack is closed.  To provide best performance, stack windows are normally unmapped rather than destroyed.  This property may be useful for those X servers with inadequate memory.  This property is also useful when debugging external commands and functions.  Externals exit when the window they use for communication is destroyed and are restarted when the window is recreated.  Setting this property allows testing many versions of an external without having to exit MetaCard.

Right.... my understanding is that when a stack is opened, two things need to occur (at least): the data needs to be read from the stack file on disk into memory, and then a window is created with its definition stored in memory and a 'handle' to that window is made available. If the stack is to be displayed, that window handle is used to draw the contents of the first card of the stack based on the stack data that's in memory.

So there's kind of two memory chunks - one for the compressed (I'm assuming) stack data, and one for the window handle. DestroyStack kills the first, and destroyWindow kills the second. If you close a stack with neither property turned on, the stack is "ignored", but both its data and its window handle remain in memory. If you later need to reopen the stack, all LC has to do is stop ignoring the stack data/handle and just use what's there. If you have destroyWIndow = "true", the window handle is purged when the stack closes, but the data remains in memory. If you have the destroyStack = "true", the data is purged, but the window handle remains in memory.

If you close a stack with destroyStack = "false", the stack will not appear in "the openstacks" (aka "the windows"), but it *will* appear in "the mainstacks", as proof that it's still in memory. This has an interesting side effect with libraries, BTW: If you 'stop using' a stack, it remains in memory even if it's destroystack property is true - you didn't really "close" it, so it remains in memory; to fully remove a library from memory, you need to "delete" that stack - just make sure that the stack you're destroying is a mainstack and not a substack, otherwise you actually delete the substack! For that reason, I tend to use something like this:

    stop using "MyLibrary"
    if "MyLibrary" is among the lines of the mainstacks then delete stack "MyLibrary"

Anyway, that's my understanding of how this stuff works - someone from the mothership can chime in and correct where I may have messed up...


Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/	

More information about the Use-livecode mailing list