[BUG]Associative Arrays Topic is solved

Discuss the future of the AutoHotkey language
_3D_
Posts: 186
Joined: 29 Jan 2014, 14:40

Re: [BUG]Associative Arrays

07 Jan 2018, 13:12

Helgef wrote:Hello _3D_ :wave:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

:beer: :beer:
AHKv2.0 use the future now.
Helgef
Posts: 3163
Joined: 17 Jul 2016, 01:02
Contact:

Re: [BUG]Associative Arrays

09 Jan 2018, 13:13

That is a classy example :)
helgef wrote:the benchmarking is flawed

Your benchmarking script has been debugged by just me, see here. You missed the little detail that the enumerator from one of the tests holds a reference to the same object as Task.List, hence, Task.List := [] didn't cause the desired outcome, you need to do _enum := "" first ;). You can also remove the timeout msgBOX after Task.List := [], there is no destruction in background when the msgBOX line is reached, it is already done.

Cheers.
_3D_
Posts: 186
Joined: 29 Jan 2014, 14:40

Re: [BUG]Associative Arrays

11 Jan 2018, 07:40

Long time I think why I chose iteration instead of just simple reference cleaning?
https://lexikos.github.io/v2/docs/Objects.htm#Reference_Counting
Known Limitations:

Circular references must be broken before an object can be freed. For details and an example, see Freeing Objects.
Although references in static and global variables are released automatically when the program exits, references in non-static local variables or on the expression evaluation stack are not. These references are only released if the function or expression is allowed to complete normally.
Although memory used by the object is reclaimed by the operating system when the program exits, __Delete will not be called unless all references to the object are freed. This can be important if it frees other resources which are not automatically reclaimed by the operating system, such as temporary files.
How the mechanism work:
1. If only one reference is stored into variable - when script exit we have guaranteed call of __delete()

Code: [Select all] [Download] GeSHi © Codebox Plus

class class_Test_1 {
__new(name) {
this.name:= name
}
__delete() {
msgBox(type(this) " >>> " this.name)
} }
var:= new class_Test_1("auto")
msgBox("exit")
ExitApp ; <<< auto call class_Test_1.__delete()
It work perfect and calling is guaranteed.
2. If only one reference is stored inside object (as static or local) - no auto release for last reference => no call of __delete()

Code: [Select all] [Download] GeSHi © Codebox Plus

class class_Test_2 extends class_Test_1 {
static reference:= ""
__new(name) {
class_Test_2.reference:= this
base.__new(name)
} }
new class_Test_2("forced") ; <<< only one reference is stored into static variable
msgBox("exit")
;class_Test_2.reference:= "" ; <<< must forced be cleared (UNCOМMENT TO CALL __delete())
ExitApp ; <<< class_Test_2.reference must be forced cleared
In this case even one only reference no call of __delete(). To call __delete() internal static variable that contain reference must be forced clear.
Conclusion:
If we need to guarantee executing of on destruction actions we need:
1. Clear all references inside objects.
2. Forced run on destruction actions.
3. Have some mechanism that prevent second run of on destruction actions (not mandatory).

Code: [Select all] [Download] GeSHi © Codebox Plus

Task.List:=[] ;no guarantee to call __delete() for all
It mean at this time (doubled references will be released when script done or when references will be released).

Code: [Select all] [Download] GeSHi © Codebox Plus

while !isEmpty {
isEmpty:= 0
for key in Task.List {
key.end()
isEmpty:= 1
} }
In this case we have guaranteed calling of __delete() (in some cases twice) at the time.
AHKv2.0 use the future now.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 6 guests