[Gc] Silently fails to allocate memory?

Basile Starynkevitch basile at starynkevitch.net
Sat Apr 13 13:24:32 PDT 2013

On Sat, Apr 13, 2013 at 02:57:47PM -0500, The Devils Jester wrote:
> On Sat, Apr 13, 2013 at 12:05 PM, Bruce Hoult <bruce at hoult.org> wrote:
> > b is allocated by the GC. The memory used internally by a to store your
> > myclass*'s is not.
> >
> > See other messages today for how to fix that.
> >
> >
> While that is something important to consider (and might have caused issues
> later on in my application), I am fairly certain that in the current
> testing process there are no vectors being used / created / resized within
> the loop.  For the sake of argument though, even if there are, would not
> the worse case scenario be exactly the same as just disabling libgc
> entirely?  This is what I keep coming back to.  With libgc disabled,
> everything works properly (other than the steadily increasing memory leak).
>  It does not run out of memory,  and all objects are created as intended.
> If I am doing something wrong, what could I possibly do that would result
> in this situation?

Use everywhere the GC. So either redefine explicitly malloc as GC_malloc (and be sure your malloc is called even 
from inside the libc) or at the very least use gc_allocator to ensure that all vectors
(even those outside of the loop you are expecting to be at issue) are GC allocated.
In a previous recent email to this list I explained how to get STL vectors which use the GC_malloc
even for their internal data.

Also, if you have a working, GC-less, variant of your program (malloc based, or new+delete based), be sure 
to test with valgrind that it does not leak memory.


Basile STARYNKEVITCH         https://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***

More information about the Gc mailing list