There are a few tools to do that, but the first thing you should do is see that you are deleting any dynamically created variables when they are no longer necessary.
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
Well, from the code you posted, if there is no delete a; after, then there is clearly a memory leak there. How I found that memory leak: I opened my eyes and looked, that's a good trick.
Seriously though, finding memory leaks can be a very difficult if you have a large code-base to plow through.
One great tool for this is Valgrind. I think VS also has decent tools for that, but I haven't tried them.
All in all, the best remedy for memory leaks is prevention. For instance, designing software with ownership relationships in mind.
Another, somewhat desperate, trick is to just make a file-search for the keyword "new" and for each one, make sure it is either immediately wrapped in a smart-pointer (with automatic storage) or that it has a corresponding "delete" (and that any deep-copy or reallocations clean up the old storage correctly).
mike_2000_17
21st Century Viking
3,142 posts since Jul 2010
Reputation Points: 2,062
Solved Threads: 625
Skill Endorsements: 41