Like This Site? 
 
RSS Feed Follow Us 

on Twitter! Be Our Fan!

C++ : Memory management and Smart pointers

Share this post!
 Vote this!

Memory management and Smart pointers

All examples will assume, you are using the newly approved but not yet officially published C++0x standard, if you can't or won't use this, all classes/constructs here are implemented in the excellent boost library as well. All examples compile with gcc 4.5.2 and the compile flags "g++ -std=c++0x", please post a comment if they do now work on your platform so I can make a note of it. Not all functions of the C++0x are implemented on all platforms.


The memory leak


Let us start by explaining the problem. Whenever you allocate memory on the heap, regardless of the fact you do it with new, new[], or the c memory allocation functions like malloc, you are responsible for cleaning it up by calling the appropriate delete, delete[] or free. If you do not or you do it wrong, you create what is known as a memory leak. This means that memory was allocated that is no longer accessible because you have no pointer any more that refers to it, but it also not freed,  more...

0 comments:

Post a Comment