This is exactly the kind of thing _gc:arc_ is designed to fix.
-gc:arc -d:useMalloc c yourProgram.nim
RunGC arc is deterministic (meaning memory will be freed immediately after Nim thinks it's done with it, i.e. C++ destructors) and useMalloc will force nim to use the system malloc / free, so memory will be directly used and returned to the operating system, without the Nim runtime holding onto the memory.
