4 ms·
"It’s a common but false belief that reference counting (using shared pointers in particular) is better than garbage collection. There is actual research showin
by eonil 13y ago
"It’s a common but false belief that reference counting (using shared pointers in particular) is better than garbage collection. There is actual research showing that the two approaches are just two sides of the same coin."
Yeah. But RC is at least deterministic and controllable side. Also, RC is just one of options of C++, while you can implement GC yourself in C++ without any overhead unlike any memory management method on GC.
- pcwalton 13y agoWithout compiler support for precise stack maps and barriers (and I don't know if it's actually possible to implement them, given how malleable pointers are in C++) the best you can do is conservative stop-the-world GC. That sacrifices a lot of performance over the incremental or concurrent GC algorithms you see in runtimes like the HotSpot JVM.
- deleted 13y ago[deleted]
- rwallace 13y agoThe article explained why RC is not deterministic.
- millstone 13y agoRC is much more deterministic than GC. Garbage collectors commonly defer object deallocation until some threshold is reached, and then do it all at once. This means that two iterations of the same loop, that do the exact same thing, may take dramatically different amounts of time. Reference counting is more stable and predictable, because the deallocation behavior depends only on the object graph in question, and not on some global state.
- millstone 13y agoThis jumped out at me too. I don’t think this point was carefully considered. For example, the Linux kernel uses reference counting - see https://www.kernel.org/doc/Documentation/kref.txt https://www.kernel.org/doc/Documentation/kref.txt . Does anyone doubt that this mechanism is better than attempting to garbage collect the kernel?