Thread overview
Hot to destroy a big Array and free RAM
Dec 12, 2018
Giovanni Di Maria
Dec 12, 2018
Jonathan M Davis
Dec 12, 2018
Giovanni Di Maria
Dec 13, 2018
Giovanni Di Maria
December 12, 2018
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.

Can you help me please?
Thank you very much
Giovanni Di Maria

December 12, 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



December 12, 2018

Hi Jonathan M Davis.
Thank you very very much.
Excuse me for the wrong forum.
Regards.
Ciao
Giovanni


December 13, 2018
On Wednesday, 12 December 2018 at 08:34:25 UTC, Jonathan M Davis wrote:
> On Wednesday, December 12, 2018 1:14:47 AM MST Giovanni Di Maria via Digitalmars-d wrote:
>> [...]
>
> 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:
>
> [...]




Hi Jonathan M Davis.
Thank you very very much.
Excuse me for the wrong forum.
Regards.
Ciao
Giovanni