The documentation clearly says that a copy of an object, say objB made from another object objA by using objB := objA actually produces two names that point to the same data in memory space. This is easily verified by observing that &objA equals &objB. Manipulation of the contents of objA are mirrored in objB as expected.
I was under the impression that a copy made with the clone() method is separate and indeed objC := objA.Clone() yields two different addresses in memory such that &objA != &objC. What surprised me is that manipulation of the contents of objA actually show up in objC as well. I'm using v1.1.24.02 64 bit. What is the correct way to create a copy of an object that will be independent of manipulations to the original object?
Relayer
Here's code that demonstrates what I'm seeing:
Code: Select all
#NoEnv
show( a := { 1 : { 1 : "=$D$1-0.75/25" }
, 2 : { 1 : "=$D$1-0.75/25" }
, 3 : { 1 : "=$D$1-0.75/25" } }, "==================`nbefore`n==================`na" )
show( b := a, "b := a" )
show( c := a.Clone(), "c := a.clone()" )
Loop % a.Length()
a[A_Index][1] := StrReplace(a[A_Index][1], "$")
show(a, "`n==================`nafter`n==================`nexpected `na")
show(b, "expected `nb")
show(c, "UNEXPECTED `nc = clone")
ExitApp
Escape::ExitApp
show(x, id)
{
static var = ""
var .= "`n" . id . " @ address = " . &x
for k, v in x
var .= "`n<" . k . ">" . v[1]
var .= "`n---------------"
Msgbox % var
}