Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Gui Option Destroy cleans Related Variables


  • Please log in to reply
3 replies to this topic
  • Guests
  • Last active:
  • Joined: --
Hi,

I sometimes need to display a GUI window just once in the script and have noticed that the command Gui, Destroy does not clear the values used in the GUI window. I'm not sure if there is a reason for it but I think destroy should mean to dispose everything whatever it contains.

We can see the variable TextHwnd still contains the value by running the code below and via the "Variable and their contents" window, the variable Text is still alive.
Gui, Add, Text, vText hwndTextHwnd, Hello World!
Gui, Destroy
msgbox % TextHwnd
return
So my suggestion is to delete variables used in a GUI window after Gui, Destroy is used, or add an option Gui, +DeleteVarsWithDestroy or something similar.

What about it.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Once Gui Add returns, there is no link between TextHwnd and the Gui. It is used only during evaluation of the Gui Add sub-command.

There are likely to be cases where a script uses Gui Submit followed immediately by Gui Destroy. In those cases, it would clearly be undesirable for Gui Destroy to clear the variables which were just updated by Gui Submit. In other cases, what benefit would there be in clearing the variables?

  • Guests
  • Last active:
  • Joined: --

There are likely to be cases where a script uses Gui Submit followed immediately by Gui Destroy. In those cases, it would clearly be undesirable for Gui Destroy to clear the variables which were just updated by Gui Submit.

I see. It is enevitable that there are users relying on the capability of the command. My personal opinion is that in such case the user should use Winhide, or a new command Gui, Close should be created. I mean there should be two different commands for closing GUI windows. One is for just hiding and the other one is for deleting.

In other cases, what benefit would there be in clearing the variables?

Assuming the possibilities of users writing scripts for a html browser, a picture viewer, or a database visualizer, which is likely to hold a large amount of information and use multiple windows, if they forget to clear variables used with the GUI windows, unused memories will be neglected and it might be called memory leak. So the benefit would be to protect users from memory leaks.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I mean there should be two different commands for closing GUI windows. One is for just hiding and the other one is for deleting.

There are three: Gui Cancel, Gui Destroy and Gui Show, Hide. That's not counting WinClose, WinHide and similar.

Assuming the possibilities of users writing scripts for a html browser, a picture viewer, or a database visualizer, which is likely to hold a large amount of information and use multiple windows,

How much data would actually be stored in the controls' associated variables? I'd guess not a lot, unless by "html browser" and "database visualizer" you mean an edit control with a whole lot of text (e.g. html or ASCII art), and you'd have some reason to submit that text into the control's variable.

So the benefit would be to protect users from memory leaks.

That's a stretch. By the same token, I could say we should remove global variables and force users to use functions with local variables, to ensure the memory is freed when the function returns.

What if the user submits the Gui without hiding or destroying it? They should clear the variables themselves once they're no longer needed.