Hi Nim community, is the following code safe or does it create a memory leak (i.e. will the values stored in the table be garbage collected or not)? import tables var strTable = initTable[string, ptr string]() proc internSting(s: string): ptr string = if s in strTable: return strTable[s] else: strTable[s] = unsafeAddr(s) return strTable[s] var a = "hello" var b = "hello" a = internSting(a)[] b = internSting(b)[] echo "a = ", a echo "b = ", b echo (a == b) echo (addr(a) == addr(b)) Run
- String "interning" attempt Serge
- String "interning" attempt Stefan_Salewski
- String "interning" attempt Serge
- String "interning" attempt Stefan_Salewski
- String "interning" attempt Serge
- String "interning" attempt Stefan_Salewski
- String "interning" att... Serge
- String "interning"... shirleyquirk
- String "interning"... Serge
- String "interning"... Serge
- String "interning"... cblake