Free memory detection tools for Delphi for QA - delphi

I have found some tools that can help the developers to find out the memory leaks like FastMM4. But can a QA person use it to determine memory leaks after we take a build? or is there any tool available that can aid a QA person to find out memory leaks then it would be great.
currently what we follow is like run the application note down the memory usage and perform some tasks and then check out the memory usage and if we find out a huge difference then we star narrowing down. Is there any tool which will do it automatically

Lots of functionality in FastMM4 can be enabled or disabled depending on a presence of FastMM_FullDebugMode.dll in system. This way you can have only one build, where leak detection will be enabled by copying FastMM_FullDebugMode.dll to program folder. Similar functionality you can achieve by using ShareMem unit together with different versions of BorlndMM.dll. In this case you can compile FastMM4 to BorlndMM.dll with any options you want.

Your QA testers can equally use FastMM to detect memory leaks. You just need to give them a build which enables memory leak detection.

SouceGuard is a lite and effective leakproof and bug reporting tool in Delphi.
It was formerly known as UMLD.

Related

Memory Profiling Existing Process in VS2012

I am not able to profile memory allocation using the VS 2012 built-in profiler when connecting to an existing web application process.
When I Start profiling and let it launch the process it works fine, but if I try and attach to an existing process it reverts to CPU sampling instead of memory allocation. There is no warning that this is going to happen.
Does anyone know of a reason why this would be the case?
Update
I'm willing to accept that this is a limitation of the profiler (although letting me know that it is falling back this to this functionality would be nice). There are ways around it.
Use a different profiler. I used this one and can recommend it.
Profile from the start and filter results.
I've certainly moved on.
This is almost certainly a limitation of the profiler. I'm sure other profilers can do this if you really need it.
The built in VS 2012 profilers are great for basic needs but for anything advanced I would go for something else.
Many of the more advanced profilers are not free, but often have a trial period. This is a good one in my opinion.
.Net Memory Profiler but SciTech Software

How best to debug Delphi using the IDE and/or FOSS?

I see the following means of debugging and wonder if there are others or which FOSS tools a small company can use (we don't do much Windows programming).
1 Debug in the IDE, by setting breakpoints, using watches, etc
2 Debug in the IDE, by using the Event Log
I got some good info from this page and tweaked it to add timestamps and indent/outdent on procedure call/return, so that I can see nested calls more quickly. Does anyone know of anything better ?
3 Using a profiler
4 Any others?
Such as MadExcept, etc?
(I am currently using Delphi 7)
The Delphi integrated debugger is powerful enough, even in Delphi 7, to handle most debugging tasks. It can also debug an application remotely. Anyway, there are situations where you may need to track different kind of issue:
To check for memory leaks, you can switch to a memory manager like FastMM4 which has good memory leak reporting. Profilers like AQTime have also memory allocation profilers to identify such kind of issues.
To investigate performance problems, you need a performance profiler. There are sampling profilers (less invasive, although may be less precise) and standard profilers (AQTime again, not cheap but very good, and others).
To trace exception, especially on deployed applications, you may need tools like JCL/JVCL (free), MadExcept or EurekaLog or SmartInspect
To obtain a log of what the application does, you can use OutputDebugString() and the IDE event viewer, or the DebugView standalone application. There are also dedicated tools like SmartInspect.
You can also convert Delphi 7 .map files to .dbg files and use an external debugger as the WinSDK WinDbg, and look at application calls in tools like ProcessExplorer
Some debugging tools may also offer features like code coverage checks (which code was actually executed, and which was never), platform compliance (check API calls are supported by a given platform), resources use and so on, but may be useful for larger developments.
Delphi 7's IDE is pretty good to start with, only look at 3rd party tools if you run into something you can't fix with what you've got:
It's error messages are informative and not excessively verbose.
The debugger is pretty good, you've got lots of options for inspecting variables, brakepoints, conditional brakepoints, data brakepoints, address brakepoint, module load brakepoint. It's call-stack view is good, it has some support for multi-threaded debugging.
Good step-by-step execution, step into, step over, run until return, etc.
3rd party tools help when you need to diagnose a problem on the client's computer (you have no Delphi IDE on the client's computer). If you can get the problem to manifest on your computer you get away with the IDE alone, no need for any addition, free or payed for.
Profiler: That's not a debugging tool. You use an profiler when you need to find bottlenecks in your application, or you need to do some speed optimizations.
Logging 3rd party frameworks: The good ones are not cheap, and you can do minimal logging without a tool (even ShowMessage works some times).
MadExcept, other tools that log exceptions: They usually require debugging information to be present in the EXE, and that's not a good idea because it makes the program slower AND it easier to hack. Again, if you can get the exception on your machine, you don't need the logger.
I'm not saying 3rd party debugging aids are not useful: they are, but I'd wait until I can clearly see the benefit of any tool before I commit to it. And in my opinion there's no such thing as free software: Even the software you don't pay for requires time to learn how to use it and requires changes to your programs and workflow.
For the bigger work, there is AQTime.
A cheaper solution for selected code is running it through Free Pascal (with the "randomize local variables option") and run it through valgrind. I've validated most my streaming code (which heavily has backwards compat constructs) that way.
Another such interesting switch is -CR, verify object method call. It basically turns every
TXXX(something).callsomething
into
if something is txx then
TXXX(something).callsomething
else
raise some exception;
Specially in code with complex trees this can give some precious information.
Normal Pascal language checking (Range, I/O, Overflow, sTack aka -Criot) can be useful too, and is also available in Delphi.
Some range check errors (often loop bounderies) that can be detected statically, will result in compile errors in (beta) FPC 3.0.x+.
You can try the "Process Stack Viewer" of my (open source) sampling profiler:
http://code.google.com/p/asmprofiler/wiki/ProcessStackViewer
(you need some debug info: a .map or .jdbg file)
You can watch the stack (also the raw stack, with "false positives" but useful when normal stack walking is not possible) of all threads, and do some simple sampling profiling.
Note: My (older) instrumenting profiler does exact profiling, is on the same site.
Not sure why you would want to upgrade to debug a problem. Yes the newer IDE's provide more features to help you debug something, but taking into consideration your previous question on how to debug your program when it hangs, I'd sooner suggest a good logging solution like CodeSite or SmartInspect. They provide way more flexibility and features than any home-grown solution based around the event log and do not require you to step through the code, like the IDE does (which affects timings in multi-threadeded problems).
Update
Sorry, didn't get that FOSS stands for Free and Open Source Software. CodeSite and SmartInspect are neither. For a free solution, you could have a look though at the logging features within the Jedi family of tools.
Rad Studio XE includes a light version of CodeSite, and AQTime, which together are both compelling improvements.
You could do a lot with JCL Debug, MadExcept, and other profiling and logging tools, but CodeSite and AQTime are the two best for their respective tasks.

Fastmm4 and leaking handles

I have just used FastMM4 to detect leaks. I did not realise our application was using a DLL which was leaking event handles and so I fixed any leaks reported by FastMM4 but not the handles as it was not reported.
My questions are, would have FastMM4 have reported the leaking event handles? Would this require me to rebuild the dlls with FastMM4 included? I also heard someone mention ShareMM, do I need to add that?
I am using Delphi2007, which I think is using the borland memory manager and if so, should I replace it with the fastMM4 one? What are the steps to do that?
Sorry for asking so many questions, I am looking at delphi after a few years of doing .net development.
JD.
No. FastMM is a memory manager, and it can only report leaks of memory that the application allocated via FastMM. Handles are opaque references to system objects that are allocated by Windows, so FastMM can't track them, and neither can any other Delphi memory manager.
And this isn't really a Delphi vs. .NET thing either, since .NET's garbage collection couldn't have solved this problem any better than FastMM can. Handles are non-memory resources and you have to keep them from leaking the same way you would in .NET: make sure that anything that allocates one releases it when you're done with it.
Do you know what type of handle you're leaking? If it's something less common than the ubiquitous HWND, that would be a good starting point in tracking down the problem: find where you're allocating that type of handle.
As for your other question, about Delphi 2007, it comes with FastMM built in, not the old BorlandMM. But it's sort of a basic version. For access to the FullDebugMode functionality, you need to download FastMM from SourceForge and add it at the top of your uses list and rebuild with the FullDebugMode compiler define on.

Simple code analyzer

Need a simple code analyzer to see if I am forgetting to free objects and classes, or to see if I am releasing them to many times.
This is built into Delphi's memory manager (FastMM). Set ReportMemoryLeaksOnShutdown true. You can also use the "full debug" version of the memory manager for more detailed checks and information.
The Pascal Analyzer from Peganza does a static analysis of your code.
AQTime from Automated QA is pretty much the defacto standard tool in the Delphi World for profiling for memory leaks (and perf of course)
Another option is a static analysys tool, the only one I know of that supports Delphi is Understand from SciTools it's pretty expensive though.
Simplest tool I've ever used for memory leak checking is MemCheck.
http://v.mahon.free.fr/pro/freeware/memcheck/

How to get the memory a function consumes

Our application consumes lots of memory and we need to identify which function cause the maximum usage of the memory. Is their any way or even any existing tool to do this(Windows, Native)?
Here is the environment:
Windows Xp
VS2008
Native C++ (MFC Based)
Thanks so much.
If you have Visual Studio 2008 Team System you can use the built-in memory allocation profiler. Here's a good MSDN article, Find Application Bottlenecks with Visual Studio Profiler using VS2008. There is also a profiler blog.
RedGate's ANTS
MemProfiler
ValGrind (free)
EDIT: since you updated to indicate C++, please also see this SO answer.
See Also:
.NET Memory Profiling Tools
Does anyone here have a favorite memory profiling/memory leak tool they like to use for their java webapps?
Best .NET memory and performance profiler?
Use a profiler. such as Automated QA's AQTime - http://www.automatedqa.com/products/aqtime/index.asp.
Most tools/profilers operate only on .NET apps which in your case is n/a
I've used Boundschecker and Purify to check for memory leaks/memory profiling for native applications (they got trial versions AFAIK) but you can also use the built in functions for this purpose if you are just interested in a one-shot analysis
look for _crtCheckMemory in your online help for a starting location.

Resources