Re: [Gc] Strange leak in simple code
Brian Beuning <bbeuning-gQiW9Mwg1h1Wk0Htik3J/[email protected]> Tue, 14 Jul 2015 17:47:09 -0400 (EDT)
| Newsgroups | gmane.comp.programming.garbage-collection.boehmgc |
|---|---|
| Message-ID | <15166426.804.1436910429638.JavaMail.bbeuning@bbeuning7> |
Garbage is defined as unreachable objects. All of your objects are reachable by following the next chain. If you added some code like this in the loop if( i++ % 1024 == 0 ) list = NULL; then only the last bunch would be accessible and all previous would be garbage and collected. Brian Beuning ----- Original Message ----- From: "Юрий Соколов" <[email protected]> To: [email protected] Sent: Monday, July 13, 2015 7:12:40 AM Subject: [Gc] Strange leak in simple code 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 _______________________________________________ bdwgc mailing list [email protected] https://lists.opendylan.org/mailman/listinfo/bdwgc _______________________________________________ bdwgc mailing list [email protected] https://lists.opendylan.org/mailman/listinfo/bdwgc