Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


c++ memory leaks detection


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 the dodger uk   Members   -  Reputation: 148

Like
0Likes
Like

Posted 26 January 2013 - 07:25 AM

is there any good programs that detect memory leaks and can point you in the right direction

i need a really good one , not even mind paying real money to buy a professional software that can do it  



Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9662

Like
0Likes
Like

Posted 26 January 2013 - 07:56 AM

For what platform/compiler? Some compilers have built in functionality for this (ex: MSVC's crtdbg.h header contains leak detection functions).

#3 swiftcoder   Senior Moderators   -  Reputation: 10360

Like
4Likes
Like

Posted 26 January 2013 - 09:40 AM

To expand a little on SiCrane's response:


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#4 Servant of the Lord   Crossbones+   -  Reputation: 20921

Like
0Likes
Like

Posted 26 January 2013 - 11:20 AM

And when running MinGW on Windows, you're out of luck for free options as far as I've looked. sad.png


Edited by Servant of the Lord, 26 January 2013 - 03:20 PM.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#5 Karsten_   Members   -  Reputation: 1655

Like
0Likes
Like

Posted 26 January 2013 - 01:18 PM

There is also IBM Rational Purify which supports GCC on Linux and Microsoft Visual C++ on Windows.


Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.


#6 Zlodo   Members   -  Reputation: 246

Like
0Likes
Like

Posted 26 January 2013 - 03:37 PM

There's also www.drmemory.org, which is similar to valgrind but also works on windows.

#7 the dodger uk   Members   -  Reputation: 148

Like
0Likes
Like

Posted 26 January 2013 - 04:15 PM

sorry , its for  windows and c++ , and not .net 

 

its  a big project and memory leaks are killing it after a bit , just trying to track down the source 



#8 Karsten_   Members   -  Reputation: 1655

Like
0Likes
Like

Posted 26 January 2013 - 04:44 PM

Are you using smart pointers such as std::auto_ptr or std::tr1::shared_ptr?

These will help prevent almost all memory leak issues and really are the way to go in modern C++. Afterall, prevention is better than cure ;)

Edited by Karsten_, 26 January 2013 - 04:45 PM.

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.


#9 belfegor   Crossbones+   -  Reputation: 2716

Like
2Likes
Like

Posted 26 January 2013 - 05:58 PM

I am using this one: http://vld.codeplex.com/



#10 Servant of the Lord   Crossbones+   -  Reputation: 20921

Like
3Likes
Like

Posted 26 January 2013 - 06:40 PM

Are you using smart pointers such as std::auto_ptr or std::tr1::shared_ptr?

These will help prevent almost all memory leak issues and really are the way to go in modern C++. Afterall, prevention is better than cure ;)

std::auto_ptr was designed badly and has been deprecated. It was designed badly because they were trying to add the features that std::unique_ptr has, before they had the actual capabilities (move semantics) to do so properly, so they worked around the problem instead of fixing the problem (the problem being a difficult and huge change, but one they successfully made in C++11). One side effect of 'working around' the problem is std::auto_ptr can't be used in most standard library containers. ohmy.png


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#11 wintertime   Members   -  Reputation: 1857

Like
0Likes
Like

Posted 27 January 2013 - 09:20 AM

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.



#12 swiftcoder   Senior Moderators   -  Reputation: 10360

Like
0Likes
Like

Posted 27 January 2013 - 10:21 AM

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 - Software Engineer @Amazon - [swiftcoding]


#13 wintertime   Members   -  Reputation: 1857

Like
0Likes
Like

Posted 27 January 2013 - 10:32 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.



#14 bioglaze   Members   -  Reputation: 624

Like
0Likes
Like

Posted 27 January 2013 - 11:31 AM

  • Visual Leak Detector
  • CppCheck
  • PVS-Studio


#15 Karsten_   Members   -  Reputation: 1655

Like
0Likes
Like

Posted 27 January 2013 - 01:33 PM

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.

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.


#16 cozzie   Members   -  Reputation: 1757

Like
0Likes
Like

Posted 30 January 2013 - 12:58 PM

Vld (visual leak detector) works great for me

#17 brx   Members   -  Reputation: 720

Like
0Likes
Like

Posted 30 January 2013 - 05:09 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS