digitalmars.D - Future Garbage Collector
- james (2/2) May 24 Hello All,
- mike_jack (42/42) May 24 This is actually a thoughtful observation, and brings up the
- Walter Bright (6/9) May 26 D allows complete freedom in selecting memory allocation strategies. The...
Hello All, Can you share thoughts on a Future Garbage Collector
May 24
This is actually a thoughtful observation, and brings up the common perspective many developers have after working extensively with garbage-collected languages like Java. In fact, your suggestion to move away from a monolithic, “one-size-fits-all” garbage collector and toward a more flexible memory management system aligns well with trends in systems-level language design. From your Java experience, it’s clear that GC behavior often becomes a bottleneck when performance is critical. With that, the developers starts slowly to focus more on GC, favoring arrays, object pooling, or stack allocations, in order to minimize the pauses or delays. That’s why your suggestion for D to treat memory management as a first-class citizen in the language and standard library is very compelling. Giving developers the ability to hint object lifetimes, force or schedule GC with timing constraints, or even plug in custom GC algorithms opens up powerful optimization opportunities. The idea of supporting multiple memory managers, each tailored for different workloads (e.g., short-lived transactional data vs. long-lived singletons), would bring D closer to giving fine-grained control like you’d see in C++, while still offering the safety and convenience of a GC when needed. Giving developers the ability to hint object lifetimes, force or schedule GC with timing constraints, or even plug in custom GC algorithms opens up powerful optimization opportunities. The idea of supporting multiple memory managers, each tailored for different workloads (e.g., short-lived transactional data vs. long-lived singletons), would bring D closer to giving fine-grained control like you’d see in C++, while still offering the safety and convenience of a GC when needed. This “open memory model” approach may really provide a feasibility for the D community to experiment and innovate. Without waiting for one universal GC to get improved, D can evolve to host a suite of GCs and memory managers. These are both optimized for different scenarios, something even Java has been slowly moving toward with G1, ZGC, and Shenandoah. To get a clearer idea of how traditional garbage collectors like Java’s operate, including why long pauses happen and what triggers them, this blog on Java Garbage Collection(https://blog.gceasy.io/what-is-java-garbage-collection/) does a great job explaining the mechanisms and trade-offs involved. It highlights exactly the sort of constraints developers run into, which makes a case for more flexible memory management approaches. In short, rather than pursuing a perfect GC, giving developers the tools and hooks to manage memory as needed might be the most pragmatic and powerful path forward for D.
May 24
On 5/24/2025 6:37 AM, mike_jack wrote:In short, rather than pursuing a perfect GC, giving developers the tools and hooks to manage memory as needed might be the most pragmatic and powerful path forward for D.D allows complete freedom in selecting memory allocation strategies. The dmd compiler itself uses all of them: 1. GC 2. stack allocation 3. malloc/free (and mechanisms based on them)
May 26