Release binary variable

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Release binary variable

16 Aug 2018, 13:45

I found that when a binary variable is routinely assigned, it does not release the memory it occupies and must be released manually. is this normal?

Code: Select all

b:=fileread(a_ahkpath,"RAW")
b:="test"
MsgBox strlen(b) "/" VarSetCapacity(b)	;4/1618432

b:=fileread(a_ahkpath,"RAW")
VarSetCapacity(b,0)
b:="test"
MsgBox strlen(b) "/" VarSetCapacity(b)	;4/30
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: Release binary variable

16 Aug 2018, 14:41

Yes, I think it's normal. Read VarSetCapacity. Memory is maintained for performance reasons.
Something related is discussed here: https://autohotkey.com/boards/viewtopic ... 37&t=51356. There are still many doubts, I do not know in what way it could affect this.

Anyway, if you are worried about this, you can ask the system for memory using DllCall, then use FileObject.RawRead instead of FileRead. Or just use VarSetCapacity(Var, 0).
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Release binary variable

17 Aug 2018, 02:27

Hello :wave:.
Yes it is normal. To free a variable you either do varsetcapacity b, 0 or b := "", that is, store an empty string. Not freeing when you do b := "test" is important because you might have set the capacity in anticipation of multiple concatenations, and b := "test" might be the initial string.

I can sympathise with this being slightly confusing since it is natural to think about the b variable as a binary type, but it is really just of type String. As was discussed in the topic Flipeador linked to.

Cheers.
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: Release binary variable

17 Aug 2018, 04:18

thank you all. I understand.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Billykid, Chunjee, icyolive, inseption86, joedf, mikeyww, Swiftly9767 and 295 guests