On Wednesday, 13 January 2021 at 18:58:56 UTC, Marcone wrote:
I've always heard programmers complain about Garbage Collector GC. But I never understood why they complain. What's bad about GC?

I want to stress: in D you can *MIX* GC with manual memory management, which gives you the best of both world.

I summarized my experience in one earlier post, (and copy & pasted below); and I also add the code to jdiutil: Just-Do-It util

https://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation

https://github.com/mingwugmail/jdiutil/blob/master/source/jdiutil/memory.d


===========================================
https://forum.dlang.org/post/hzryuifoixwwywwif...@forum.dlang.org

One of the upside of D I like is that one can mix GC with manual memory management:

https://dlang.org/library/core/memory/gc.free.html

which gives you the best of both world.

Currently I have a personal project, initially I was solely relying on GC just like in Java: allocate all the objects via `new`, and let the GC take care of all the bookkeeping. But there is a particular set of objects which takes the majority of memory consumption of the program, and even after I carefully removed all the reference after the object is no longer used, the program still use lots of memory because GC collection is un-predictable, both in terms of timing and efficiency.

Then I decided to do manual core.memory.GC.free just for that particular objects, (it was not very easy in a multi-threaded program to make all the logic right, but eventually I got it done). And the resulting program now only use ~10% of the memory it used to use.

I think this flexibility to mix GC & manual memory management is very unique in D. Actually I'm not sure if it can be done in other languages at all.
===========================================


Reply via email to