viernes, 29 de octubre de 2010

Smart pointers. shared_ptr and normal pointer

Shared pointer can make our code more secure. shared_pointer is a kind of pointer that allow to others pointer share his container. And when no pointer points to a container, the garbage collector erase the container thus ensuring the reliable of the program in order to no consume the heap of the process.

If we use the next code, the above behaviour.

The follow code show the common error, creating new pointers and not erase the container.

If we compile and execute this two codes, we obtain the next statistical result: