Run-time errors and memory leaks detection - visual-c++

Created application is working toooo slow, looks like there are a lot of memory leaks, there are a lot of pointers. So, please, can you advice some effective tool for run-time errors and memory leaks detection in Visual Studio C++?

You can use deleaker. It must help you.

I know 2 good tools for windows: Purify and Insure++.
For linux: Valgrind.

If you use the debug version of the CRT library , you can use find all memory leaks very easily.
Basically after including appropriate headers you call
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
somewhere in the beginning of you program.
Before the program exits you should call
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
Which dumps all the memory leaks to Debug Output Window.
But the application being slow might be unrelated to memory leaks, For performance profiling you can follow directions as per Find Application Bottlenecks with Visual Studio Profiler
For catching bad C++ constructs at compile time, you can use the static code analysis feature of Visual Studio 2010 or later.

Related

VLD causes issues

ALL,
I have MSVC 2017 Community and trying to find where is the memory leak in my program.
I did compile and link against the VLD and I did copy vld_x86.dll, dbghelp.dll and Microsoft.DTfW.DHL.manifest to the same place where executable is.
Trying to run the program under MSVC I am getting
wntdll.pdb not loaded
exception.
If I build without VLD, program starts without any issues.
What is a way to debug memory leaks with MSVC?
TIA!!

Memory profiling on Visual studio 2012 PRF0025 error

I implemented big program to find nearest neighbor using kd-Tree. But when I test it, used memory is bigger and bigger. I tried this advice, bud still not working. (No data collected when profiling .NET class library with Visual Studio 2012)
output of profiler:
Profiling started.
Warning VSP2355: Some Windows counters will not be collected. Without this data, some performance rules may not fire.
Profiling process ID 10112 (KdTreeNN).
Process ID 10112 has exited.
Data written to C:\<path>\KdTreeNN\KdTreeNN140529.vsp.
Profiling finished.
PRF0025: No data was collected.
Profiling complete.
Some other advices? Please help. Thanks

What is the best way to trace down memory leaks

In a huge C++ builder 2010 application with several DLL's being built and linked etc. What would be the best way to trace down memory leaks that accumulate over a long period of time? Say that the application has to be running for a week or something on the target machine before it becomes an issue. Let's assume that there is no profiling application available like AQ Time or something similar. Just using the standard IDE and perhaps some code.
My initial idea was to write a macro to use in all classes that keeps track of the number of instances and space used of each class type to start with.
The RTL uses FastMM as its memory manager. FastMM supports memory leak reporting and tracing. The native version of FastMM that is included in the RTL is a stripped down version, but it does support minimal leak reporting. You can set the RTL's global ReportMemoryLeaksOnShutdown variable to true at run-time and FastMM will generate a basic leak report when the app is closed. For more advanced usage, you can download the full version of FastMM and add it to your app, which will replace the RTL's native version. You can then configure FastMM as desired.

How does one go about fixing a memory leak?

I've got this game server that whether i download the pre-compiled binary or compile the source code myself just leaks until i have to reboot or enter a BSOD. I'm not super keen on C++ just currently classes for my degree but i can look at the code and understand whats going on. I'm just not 'fluent'.
Specifically looking at the resource monitor the modified memory type just fills and fills constantly by about 3-5MB per 5 seconds
is there anything i can do about this?
There is tool which is helpful for finding memory leaks: http://valgrind.org/
If you have ever ever heard about a tool called valgrind you can run your C++ code in valgrind to see exactly where the leakages are.
http://valgrind.org/

dll size (debug and release)

I have read in other discussions that Release dlls have reduced size compared to Debug dlls. But why is it that the size of the dll I have made is the other way around: the Release dll is bigger than the Debug dll. Will it cause problems?
It won't cause problems, its probably that the compiler is 'inlining' more items in the release build and creating larger code. It all depends on the code itself.
Nothing to worry about.
EDIT:
If you are really worried about and not worried about speed you can turn on optimize for size. Or turn off auto inlining and see what difference you get.
EDIT:
More info, you can use dumpbin /headers to see where the dll gets larger
How much bigger is your Release DLL than your Debug DLL?
Your Debug DLLs might seem small is you are generating PDB symbol files (so the debug symbol is not actually in the DLL file). Or if you are inadvertently compiling debug symbols into your Release DLL.
This can be caused by performance optimizations like loop unrolling - if it's significantly different, check your Release linker settings to make sure that you're not statically compiling anything in.
The performance can be influenced if your application perform tasks of high performance. A release version can even be larger than a debug version, if marked options to generate code with information on Debug included. But this also depends on the compiler you are using.

Resources