Hot to destroy a big Array and free RAM

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Dec 12 08:34:25 UTC 2018


On Wednesday, December 12, 2018 1:14:47 AM MST Giovanni Di Maria via 
Digitalmars-d wrote:
> How to delete an array and to free RAM
>
> Hi. Can you help me please?
> I have tried many experiments but without success.
> I have a big array of arrays (matrix[][]).
>
> After to have filled of data i measure the RAM with an utility
> (for example Wise Memory Optimizer).
>
> Then i try to destroy the array in many modes, but the free RAM
> is still the same.

As I understand it. under normal circumstances, the GC never returns memory
to the OS. Even if it's collected during a GC cycle, it keeps it around so
that it can be reused when the GC needs to allocate memory again. That being
said, looking at the documentation for core.memory, it looks like
GC.minimize might return unused memory to the OS if it's called:

https://dlang.org/phobos/core_memory.html#.GC.minimize

Regardless, you'll need to make sure that there are no references remaining
to any portion of that memory in your program, or the GC won't even collect
it. The program must no longer have access to any portion of the allocated
block for the GC to be able to safely collect it.

Worst case, if you need more control over how the memory is returned to the
OS, then you may need to use malloc/free or one of the allocators from
std.experimental.allocator rather than using the GC.

BTW, questions like this belong in D.Learn. This newsgroup/forum/list is for
general D discussions, not for questions related to learning how to use D.

- Jonathan M Davis





More information about the Digitalmars-d mailing list