You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
-mm=rc: const b = a (a let of a class) takes no reference; reassigning a frees what b holds #454
Under -mm=rc, const b = a, where a is a let holding a class instance, does not keep the instance alive. Reassigning a frees the object while b still refers to it.
classNode{v=0;name="";}functionmain(){leta=newNode();a.name="first"+1;constb=a;a=newNode();letkeep: string[]=[];for(leti=0;i<1000;i++)keep.push("k"+i);assert(b.name=="first1","b still holds the first node");print("done.");}
rc: assertion failed: b still holds the first node, exit code 3. The first Node and its string are freed when a is reassigned, and the keep loop reuses the memory.
The same program with only a number field (v) passes under rc, because the freed block is not reused before b.v is read. The bug is still there, it just does not show.
Probable cause: a const initialised from a let is folded into a read of the let rather than given storage and a reference of its own. Branch own-shared (own phase 8) fixed this for Shared<T> handles only, by giving a const of that type identity storage (needsIdentityStorage, beside ArrayType). Class instances still need the fix.
Activity
A const object literal holding a borrowed field has a slot of its own (…
A const record whose field is made for it has storage, as a let does (#…
rc: a const read out of a field keeps a count of its own (#635)
A const interface or bound method made over a local holds what it sho…