c++ memory leaks detection

Started by
15 comments, last by brx 11 years, 2 months ago

If you like doing it yourself there is always the possibility of overriding global new and delete operators (normal and array version) and possibly use some makro magic to include __FILE__ and __LINE__ in the calls inside of files where you expect errors (that needs 1 more operator for all variants), when doing a debug build. Then collect data in there and print out a log for calling wrong operator delete, deleting twice and remaining allocations at end of your program.

Though using some premade library would probably give you better results.

Advertisement

If you like doing it yourself there is always the possibility of overriding global new and delete operators

I don't terribly recommend this approach. It can play havoc when your project incorporates DLLs, as the correct new/delete operator isn't always used across DLL boundaries...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Yeah as said I would only do that in a debug build not on your release.

Also its safer anyways to not allocate anything inside one dll and deallocate it outside and then there should be no problem. If there is one, it just brought a possible bug to surface, which was the point of overwriting it.

  • Visual Leak Detector
  • CppCheck
  • PVS-Studio

Aether3D Game Engine: https://github.com/bioglaze/aether3d

Blog: http://twiren.kapsi.fi/blog.html

Control

std::auto_ptr was designed badly and has been deprecated.

Yeah true, so can't really be called "modern C++". But it is better than using "raw" pointers for everything I suppose.

<offtopic>
Though personally I always find it a tossup between using the deprecated auto_ptr or dragging in boost as a dependency when tr1 isn't available.
</offtopic>

My favorite solution though is to just write code modules in a cross platform manner and use Valgrind in a VM to test them before release. Especially when developing on embedded platforms or OpenBSD.
http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.
Vld (visual leak detector) works great for me

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

To expand a little on SiCrane's response:

QFT.

This is some very good advice and so far you did not comment on even trying it.

This topic is closed to new replies.

Advertisement