
Techniques for investigating untypical Go memory leaks - pavfarb
https://www.cossacklabs.com/blog/investigating-go-memory-leaks.html
======
leovonl
"When we've initially started [..], dominant was Go 1.3, which had mechanisms
to detect memory blocks allocated inside used libraries and all such blocks
were to be freed by GC. Go 1.6 significantly improved its memory management,
however as part of those improvements memory allocated by external libraries
was no longer garbage collected by the runtime."

This looks like a serious API break.

To be fair, the whole idea of the runtime automagically managing external
memory gives me shivers, and this looks like moving in the right direction - I
just think it was not very wise to go with that initial decision in the first
place.

~~~
josefx
May not have been a "decision" at all. The simplest GC just needs to hijack
malloc to keep track of allocations and every now and then scan the process
memory for values that look like pointers into those allocations. Of course
that is both slow and leaks bad enough that early Go versions had issues with
32bit address space.

------
ankurdhama
"var output = (*byte)(unsafe.Pointer(m))" This will give you the pointer to
the byte slice object which may have its own structure which is opaque to you
and this is not same as "getting the pointer to C byte array". It is weird
that it was producing correct results at all :)

------
giantahead
Techniques for noticing you're almost shooting yourself in the leg, then
suddenly saving the situation very last moment, mi amigo :)

------
yandrypozo
This remember me one of the Go Proverbs, Cgo is not Go
[https://www.youtube.com/watch?v=PAAkCSZUG1c&t=12m37s](https://www.youtube.com/watch?v=PAAkCSZUG1c&t=12m37s)

~~~
pavfarb
But, as he says, 'sometimes you have to'. This is a time like this.

------
bkeroack
Don't use cgo (or any dependencies that use it) if you can at all avoid doing
so.

~~~
pavfarb
If we could avoid doing so - we would, because we understand how hard earned
Go's guarantees are. But, things are the way they are.

