C++: Difference between revisions

No edit summary
Line 72: Line 72:
==== Garbage Collection ====
==== Garbage Collection ====
Traditional C++ does not have garbage collection.   
Traditional C++ does not have garbage collection.   
After using `new` to allocate an object, use `delete` to deallocate it.   
After using <code>new</code> to allocate an object, use <code>delete</code> to deallocate it.   
You can also use C allocation with `malloc`, `calloc`, `alloca`, and `free`.
You can also use C allocation with <code>malloc</code>, <code>calloc</code>, <code>alloca</code>, and <code>free</code>, though it is [https://stackoverflow.com/questions/184537/in-what-cases-do-i-use-malloc-and-or-new not recommended] since these are not type-safe.
If using C++14, you can use [https://en.cppreference.com/w/cpp/memory/shared_ptr shared pointers] which does have automatic garbage collection.
In C++14, you can use [https://en.cppreference.com/w/cpp/memory/shared_ptr shared pointers] which does have automatic garbage collection.
 
 


==Programming Styles==
==Programming Styles==