On Sun, Apr 7, 2019 at 12:30 PM Tharen Abela <abela.tha...@gmail.com> wrote:
>
> The gist of the problem is that I am allocating an object in the runtime, 
> (which I refer to as the batch struct), and the GC is deallocating the 
> object, even though a reference is being kept in a slice (similar to allp and 
> allm).
> While allocating, I call acquirem to prevent the GC being triggered, during 
> which I append the batch pointer to the slice.
>
> From running `GODEBUG=gccheckmark=1` I know that the batch object allocated, 
> was being freed, yet when it crashes it says the object is being marked 
> (hence marking a freed object).
>
> Now my intention is to keep the batch allocation till the end of the program, 
> keeping it in an extra batch queue, so it should not be freed.
>
> Thinking about it now, I am not sure if the deallocation occurs after the 
> work of the program is finished and is winding down, by de-allocating 
> everything, but a reference is still kept in allb, so a double free will 
> occur, OR,
> what I have been assuming so far, that this takes place while work is 
> incomplete so the GC is incorrectly de-allocating a batch object still in use.
>
> Another thing to take note of, is that the batch in P is referenced by a 
> uintptr, I'm not sure how that might affect it.

That is going to be your problem.  The GC only tracks values with live
pointers.  A value of type `uintptr` can not be a live pointer.  The
runtime can only get away with the `guintptr`, `muintptr` and
`puintptr` types because it knows that there are existing other
pointers to all G and P values (in the allgs and allp slices and the
allm linked list).  If there is ever any moment that your batch
objects are only referenced by `uintptr` values and not by a value of
pointer type, then the garbage collector can collect it.

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