I'm using callbacks at several places in the code. The callbacks are being run in threads created by a runtime system outside the nim runtime which has no clue about them. The callbacks first calls a nim raw function trampoline which then calls a stored nim closure.
When using the allocator in the callback, like allocating a small string the nim runtime allocates first 4096 bytes and then 0.5MB for every time the callback is being called. This is about what also happens during process startup so it is like the allocator believes that there is an empty heap every time in the callback.
No memory is ever returned using osDeallocPages when the callback exits.
The GC used is ARC/ORC (same behaviour)
For ARC/ORC setupForeignThreadGc() and tearDownForeignThreadGc() are completely empty which suggest that ORC is supposed to work with foreign threads out of the box. The question is if that's really the case.
Try -d:useMalloc.
Yes, that works without any problems or leaks.