19.3 Comparing C and C++ Approaches

C:

  • Raw pointers are integral and must be managed manually.
  • Frequent malloc() and free() calls.
  • Common errors include double frees, memory leaks, and dangling pointers.

C++ Smart Pointers:

  • std::unique_ptr and std::shared_ptr automate cleanup, reducing manual new/delete.
  • They rely on runtime checks or reference counting.
  • Cycles or subtle issues can still occur if not carefully managed.