Do we need to free memory by using var:="" if variable is local to function? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
john_c
Posts: 493
Joined: 05 May 2017, 13:19

Do we need to free memory by using var:="" if variable is local to function?

19 Jul 2022, 06:48

Do we need to free the memory by using var := "" if the variable is local to a function?

An example of what I'm talking about:

Code: Select all

CopyToPseudoClipboard(ClipWaitTimeout := "") {
  ClipSaved := ClipboardAll()
  A_Clipboard := "" ; Required for ClipWait
  Send("^c")

  if (ClipWait(ClipWaitTimeout)) {
    PseudoClipboard := A_Clipboard
  }

  A_Clipboard := ClipSaved
  ClipSaved := "" ; Free the memory in case the clipboard is very large. Am I right that this line is excessive?
  Return(PseudoClipboard)
}
User avatar
boiler
Posts: 17399
Joined: 21 Dec 2014, 02:44

Re: Do we need to free memory by using var:="" if variable is local to function?  Topic is solved

19 Jul 2022, 12:40

Per the Functions documentation:
Local Variables wrote:All local variables which are not static are automatically freed (made empty) when the function returns, with the exception of variables which are bound to a closure or VarRef (such variables are freed at the same time as the closure or VarRef).

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Descolada, just me and 43 guests