[m-users.] Memory management confusion

Volker Wysk post at volker-wysk.de
Sun Apr 20 03:43:27 AEST 2025


Hi.

I'm a little confused about memory management. I've read "Memory management
for C" in the Language Reference Manual and the comments in
mercury_memory.h.

In there is this:

// These routines all allocate memory that will be traced by the
// conservative garbage collector, if conservative GC is enabled.
// (For the native GC, you need to call MR_add_root() to register roots.)
// These routines all check for a null return value themselves,
// so the caller need not check.

But what happens when such a null return value is detected?

And one of "these routines" (see above) is MR_GC_NEW. In lines 1028/1029 of
the ODBC extra library is this:

    // Doing manual deallocation of the statement object.
    Statement = MR_GC_NEW(MODBC_Statement);

According to mercury_memory.h, memory allocated by MR_GC_NEW is GC-traced.
This means that it is registered for later deallocation as well as searched
for pointers to other registered memory blocks. It *does* get garbage
collected. Why does the comment say "Doing manual deallocation"? Is this a
documentation error? Or what could be meant by that comment?

Actually, the memory does get deallocated manually, in the predicate
cleanup_statement.

Cheers,
Volker


More information about the users mailing list