Re: When's GCunref() necessary

2019-01-02 Thread Araq
> dest not on stack and src is not nil, so ref is increased? Hmm, that's a good point. I need to think about this. > Is it legal to continue to use x? Yes.

Re: When's GCunref() necessary

2019-01-02 Thread liwt31
Thanks. But I'm still under the impression that `d.s = "abc"` increases the ref count of `"abc"`. If I understand correctly `d.s = "abc"` will lead to the execution of the following function: proc unsureAsgnRef(dest: PPointer, src: pointer) {.compilerProc.} = #

Re: When's GCunref() necessary

2019-01-02 Thread Araq
The manual is completely wrong here. `GCunref` needs to be paired with `GCref`, always. And indeed you need the GCref in order to keep the GC from collecting the string too early.

When's GCunref() necessary

2019-01-01 Thread liwt31
I noticed the following example in the nim manual to demonstrate how to use an untraced object: type Data = tuple[x, y: int, s: string] # allocate memory for Data on the heap: var d = cast[ptr Data](alloc0(sizeof(Data))) # create a new string on the