Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why doesn D use reference counting for garbage collection?

0
Posted

Why doesn D use reference counting for garbage collection?

0

Reference counting has its advantages, but some severe disadvantages: • Cyclical data structures won’t get freed. • Every pointer copy requires an increment and a corresponding decrement – including when simply passing a reference to a function. • In a multithreaded app, the incs and decs must be synchronized. • Exception handlers (finally blocks) must be inserted to handle all the decs so there are no leaks. Contrary to assertions otherwise, there is no such thing as “zero overhead exceptions.” • In order to support slicing and interior pointers, as well as supporting reference counting on arbitrary allocations of non-object data, a separate “wrapper” object must be allocated for each allocation to be ref counted. This essentially doubles the number of allocations needed. • The wrapper object will mean that all pointers will need to be double-dereferenced to access the data. • Fixing the compiler to hide all this stuff from the programmer will make it difficult to interface cleanly wi

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123