On Thursday, December 21, 2017 12:00:17 Mike Franklin via Digitalmars-d- learn wrote: > I'm not a big user of the standard library, but I believe most > features of the standard library require the GC.
Actually, relatively little in Phobos explicitly uses the GC. There are some things that definitely do (e.g. std.array.array), but the vast majority is range-based and doesn't explicitly allocate anything. The main problem is that lambdas often result in the compiler deciding that a closure needs to be allocated to ensure that the code is @safe with regards to the stack variables that the lambda accesses. So, for a lot of stuff, if you just use stuff like static nested functions or functors instead of lambdas, you won't get any GC allocations, but there are certainly places where the library allocates where it shouldn't (e.g. one range-based function calls another with a lambda that results in an allocation), and more work needs to be done to ensure that all of the stuff like that is caught and fixed. So, if you want to avoid the GC, you do have to be careful with Phobos, and Phobos does need some improvements to remove inadvertent uses fo the GC, but relatively little in Phobs allocates memory. Most problems that someone is likely to have with the GC stem from their own code, not the standard library. And actually, idiomatic D does tend to reduce how much your typical program allocates (e.g. lots of structs on the stack and preferring lazy ranges to arrays), which means that the GC typically has a far lower impact than many people assume that it will - though if someone is writing their code like it's Java and uses lots of classes and puts most stuff on the heap, then they're bound to have performance problems. - Jonathan M Davis