Re: [Gc] Strange leak in simple code

Ingo Albrecht <[email protected]> Wed, 15 Jul 2015 17:32:24 +0200
Newsgroups gmane.comp.programming.garbage-collection.boehmgc
Message-ID <[email protected]>
On 07/13/2015 01:12 PM, Юрий Соколов wrote:
> Using libgc from Ubuntu 15.04 (7.2b-6.4) this simple code leaks:
>
> |    #include <gc.h>
>
>     struct list {
>         struct list* next;
>     };
>     
>     int main() {
>         GC_INIT();
>         struct list *last = NULL;
>         for (;;) {
>             struct list* nuo = GC_MALLOC(sizeof(struct list));
>             nuo->next = NULL;
>             // if next line is commented, then no leakage
>             if (last) last->next = nuo;
>             last = nuo;
>         }
>     }|

Note that this code works, even on Debian and Ubuntu, when a call to
GC_gcollect() is inserted anywhere in the loop. This may either be because
libgc doesn't collect otherwise (unlikely) or because the additional
call clobbers
registers that would otherwise contain an ambiguous reference to the first
list node (more likely). Note that compiler optimization will affect
results here!

Your example, while short and concise, is a bad test for this kind of
conservative
GC since it does not create enough perturbance on the stack to
effectively erase
old references. Also your allocation pattern, while entirely valid, is
unusual in that
it contains extremely long reference chains that are hard to collect for
any collector.

Rest assured that this will not happen for more realistic usage. It is
just an artifact
of how conservative GC works.

>
>
> stackoverflow question
> http://stackoverflow.com/questions/31380641/libgc-why-this-code-leaks
>
>
> _______________________________________________
> bdwgc mailing list
> [email protected]
> https://lists.opendylan.org/mailman/listinfo/bdwgc

_______________________________________________
bdwgc mailing list
[email protected]
https://lists.opendylan.org/mailman/listinfo/bdwgc