Collecting garbage: why and how

Here are some reasons for using smart pointers and the garbage collection system in programming:

  • Fewer bugs: Using smart pointers means the automatic initialization and cleanup of pointers. No dangling pointers will be created because they are always reference-counted.
  • Efficient management: Objects will be reclaimed as soon as they are no longer referenced, which gives more available memory to applications with limited resources.
  • Easy to debug: We can easily obtain the referenced counting number and other information on objects, and then apply other optimizations and experiments.

For instance, a scene graph tree is composed by a root node and multiple levels of child nodes. Assuming that all children are managed with ...

Get OpenSceneGraph 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.