Wargan, jmm72 thanks a lot!
"set the length of the 1st dimension of the array to 0 safely" should do it.
P.S. I wasn't talking about memory leaks, but the situation is the following:
I generate a game map in a thread (let's those be 8 threads).
At some point threads peak their memory consumptions (when checking for map consistency).
Eventually they finish and stop waiting until other code (a generation manager) "takes" and "saves" the maps.
During this time more threads can start which will also require some memory.
So, just to minimize the memory use I can "free" some of the temporary arrays, so that RAM frees up for next processes.
e.g. the cycle looks like:
Generation class create
Init parameters
Start thread
Make temporary arrays (use a lot of RAM in case the map is big
)
Process the map
Free temporary arrays (free those megabytes)
Halt and wait for the data to be copied
External manager frees the generation class