A method to detect memory leak in C++