Strings used as object keys get freed by the garbage collector #5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When a string is used as an object key, but is not stored anywhere else, the garbage collector frees it, while it is still in use as the object key.
This happens because the object key type is a plain
stringtype instead of aStringvalue, which means it cannot be marked during GC.Reproducible code:
I fixed the bug by tracking strings used as keys in a separate map in
the Object struct. I know this is not a very performant or memory
efficient solution.
I considered doing string interning, but that seems too annoying to
implement for now. This is something I can consider in the future.