Monthly Archives: December 2014

Smart pointers vs Raw pointers

In c++ you use pointers very often, and they are the main reason for memory leaks and other problems. They allocate memory and if they are not deleted that is a memory leak. To avoid this problem the Smart pointers are to prefer.

A Smart pointer contains a Raw pointer – pointing to it, and it has the same size -, only the Smart pointer deletes the Raw pointer when it is no longer used. This means that you don’t have to worry about forgetting to delete it yourself.

This is an example from MSDNs website that shows the difference between the different pointer types:


The Smart pointer is then used just as a Raw pointer with the operators -> and *, but it has also got its own member functions which you can reach by using the dot like; smart_pointer.member_function();

This is a very useful pointer and I will absolutely be reading more about this and start to use Smart pointers instead of Raw pointers. But this is as far as I have gotten in researching this topic so far!


Visual Leak Detector – File and line number not available

When using Visual Leak Detector (vld) there are some problems you might encounter. The problem (I thought I had) was that it wouldn’t show what file and line number it found the memory leaks in. No matter how much I searched for this on google no one seemed to give me an answer that worked.



When the running was done the top line of the vld output said (inside the green rectangle): “0x0F37C260 (File and line number not available): MSVCR120D.dll!operator new”. And where “File and line number not available” is; I thought the actual file and line number was supposed to show. This is however not the case!

It is the line after that which tells you where the leak is (inside the orange rectangle). The text before the orange arrow tells you which file has the leak, and the number the arrow is pointing to is the line number in the file. The text after the number tells you which method the leak is in. Then it’s just finding and correcting the leak and you’re done!