I am going to give it firmly "very possible."
One form of memory leak is when a function allocates memory and does not remove it from at least one path from the function. Some area pointer, such as auto_ptr , can handle this very well. (Note: auto_ptr was part of the first ISO standard, and it is deprecated in the next, so it’s hard to give recommendations on which pointer to use for the scope. Consult your compiler and library documentation to find out what they support.)
Another form is where the object is allocated and the property is divided, which means that there is more than one procedure that uses it, and there is no easy way to tell if everything is connected with it. This is a good candidate for shared_ptr , but you should use some caution. When creating an object, assign shared_ptr and make sure that every other pointer uses shared_ptr . If routines A, B, and C access the object through shared_ptr , and you have not changed D, then when routines A, B, and C pass through it, it leaves, regardless of the needs of D.
One thing you want to avoid with shared_ptr is loops, because if I have shared_ptr to J, J has a shared_ptr to K, and K has a shared_ptr to I, none of them are ever deleted , even if they are not available anywhere in the program. You need to monitor these situations. You can break them into weak_ptr in a loop or delete an element in a loop yourself or just live with a leak.
Another thing to consider is replacing vector and similar containers for dynamically allocated arrays and other dynamically allocated data structures. This gives you plenty of free time to manage your memory, although you can still flow from memory anyway. If the vector becomes large and then becomes small, it will not free up excess memory. A common practice, if you really need to recover memory, is to swap once a large vector with a copy of itself.
In short, there are many very useful tools for automating memory management, but they do not replace thinking on your part. Many problems can be solved by simply turning each pointer into shared_ptr and each array into vector , but using it wisely will give even greater benefits.