3

I am developing an application in C++ using visual studio 2015 Community Ed. My app runs pretty well at first but within a few minutes it begins to grind to a halt. This says to me that it is a memory leakage. I've gone through the code following the advice given in the answer to this question. I've looked at deleaker as suggested but it runs for $100 which I'd rather not spend if possible. At the current rate it is running my app never exits so using the CRT library as described here doesn't seem feasible. Has any one found any good 'live' profilers particularly good for finding where a memory leak occurs on windows that are free (Preferably something that works with VS2015)?

Community
  • 1
  • 1
Nick
  • 862
  • 12
  • 35
  • Try using `valgrind`. – Eli Sadoff Jul 03 '16 at 20:27
  • @EliSadoff Valgrind is not available for Windows. – dgrine Jul 03 '16 at 20:37
  • 2
    Don't use constructs that are prone to memory leaks, i.e. raw pointer usage, usage of `new[]`, etc. Using containers, smart pointers, RAII, etc. reduces or totally eliminates memory leaks. I've never had to diagnose a memory leak in a few years, all due to using the techniques described. – PaulMcKenzie Jul 03 '16 at 20:44
  • @OnMyLittleDuck Well, [this is SO](http://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows). ;-) – skypjack Jul 03 '16 at 20:48
  • It sounds like it could be a leak, but have you actually verified that is the problem? – bennji_of_the_overflow Jul 03 '16 at 21:32
  • When was the code last running without this slow-down, and what changes have you made since then? (You have been testing the code, haven't you?) – Beta Jul 03 '16 at 23:28
  • I recommend you look at the debug heap in Visual Studio. crtdbg.h in a debug build will detect leaks. After `main()` exits it will enumerate all heap allocations that were not allocated by the CRT itself. I recommend using it in all compilation units to get the most complete report. It does a lot more than leak detection (e.g. writing over de-allocated memory, heap corruption, writing beyond a memory allocation). [This article on MSDN](https://msdn.microsoft.com/en-us/library/x98tx3cf.aspx) is a great place to start for the leak detection capability. – David Thomas Jul 04 '16 at 00:25
  • `//stdafx.h includes #define _CRTDBG_MAP_ALLOC #include ` and `int wmain() { _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG)); auto leaked_mem = new char[5]; }` will report `Detected memory leaks! Dumping objects -> {112} normal block at 0x00E5EAB8, 5 bytes long. Data: < > CD CD CD CD CD Object dump complete.` – David Thomas Jul 04 '16 at 00:44
  • VLD can help with this: https://vld.codeplex.com/ – drescherjm Jul 04 '16 at 01:39

0 Answers0