On Fri, Oct 5, 2018 at 3:53 PM,  <flockemar...@gmail.com> wrote:
>
> I'm still a newbie. I've got a factory function for objects, and the newly
> created object is given out by a return statement.
>
> But it seems the original object gets copied (no "move semantics") and gets
> garbage collected. Anyway, in my program, my custom finalizer (set with
> runtime.SetFinalizer) gets called on it, unless I use pointers.
>
> My first question was whether I understand this correctly at all.
>
> ...
>
> And, in general I will try to use value-ish code. Because it looks neat and
> the stuff to copy isn't too much when I don't have a lot fields. And when I
> have custom finalizers I can still use pointers to objects.
>
> Or would I better let all factories (even thouse without custom finalizer)
> give out pointers?

1. When discussing the details of some piece of code, it helps a great
deal to show us the code.

2. As a general guideline, don't use finalizers.  They are hard to use
correctly and have various problematic cases; see the docs for
runtime.KeepAlive (https://golang.org/pkg/runtime/#KeepAlive).

3. Finalizers are always associated with a specific pointer.  If there
are no longer any references to that pointer, the finalizer may run.
There is no such thing as a finalizer on an object, finalizers are
always on pointers.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to