TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  OAL#011Checked automatically with code checker

Synopsis:Use smart pointers for memory management
Severity Level:2
Category:Object Allocation


Smart pointers are pointers that free their allocated memory automatically when they go out of scope. In this way, memory leaks are avoided automatically.

Example (wrong):

void m() {
  MyObject* ptr = new MyObject(); 
  ptr->DoSomething(); // Use the object in some way
  delete ptr; // Destroy the object. Done with it.

Example (correct):

void m() {
  std::unique_ptr<MyObject> ptr(new MyObject());