Re: [Gc] Strange leak in simple code

Юрий Соколов <[email protected]> Wed, 15 Jul 2015 05:52:04 +0300
Newsgroups gmane.comp.programming.garbage-collection.boehmgc
Message-ID <CAL-rCA2VQpJV1nqFyAAeOPSpLK0fT6sxwbFMNNm=_+iLaZp25A@mail.gmail.com>
Read the code carefully.  This code keeps pointer only to last node. So
only two nodes are reachable at max.
What do you mean "it leaks?"

You're making a linked list, with every object pointed to either by 'last'
or by the previous object.

I would be very very unhappy if this was garbage collected!!


On Mon, Jul 13, 2015 at 11:12 PM, Юрий Соколов <[email protected]>
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;
>         }    }
>
>
>
> stackoverflow question
> http://stackoverflow.com/questions/31380641/libgc-why-this-code-leaks
>
> --
> This message has been scanned for viruses and
> dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is
> believed to be clean.
> _______________________________________________
> bdwgc mailing list
> [email protected]
> https://lists.opendylan.org/mailman/listinfo/bdwgc
>

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