Simple code analyzer - delphi

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/

Related

Free memory detection tools for Delphi for QA

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.

Measure How much memory a program will need

Is it possible to know how much memory a program will need?
The usual method is to use some form of profiler. Many IDEs include their own, Netbeans for example has a particularly good profiler (in my opinion) for Java applications. This will show the memory consumption of your program as its running, and is good for testing for things such as memory leaks as well as overall consumption.
If you've only got the binary, then you'll just have to use a basic tool such as task manager or pmap. This won't give you nearly as much detail though.
if you're using an IDE then it will probably have some in-built feature by which you can see the same...
In case you are executing directly, I guess probably the Task Manager is the best way.

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.

How to find "fat" procedure memory usage?

While working on my code lately, I've noticed that some of the memory usage is going up significantly, and I can't see many reasons for it in my code. So I'm wondering if there are any programs, techniques, or other types of tools that can scan my code (Delphi) and estimate for me what procedures, functions, and functions will be the heaviest memory users. Ideally, I' think I'd be looking at the code as it is run in debug mode, but if something can scan the source files and tell me, that would be even better. Thanks.
The type of tool you are looking for is a Profiler. There are lots of good profilers out there for most languages. I'm less familiar with Delphi though so I used google and it turned the following options
http://www.prodelphi.de/
http://delphitools.info/
But the best information seems to be on this question from StackOverflow
Delphi Profiling tools
See my answer to a similar question:
Memory profiling tool for Delphi?
Without knowing how you are currently measuring "memory use" it's difficult to say what might be the best tools to use.
We have used AQTime in the past it found a load of memory leaks.
http://www.automatedqa.com/products/aqtime/
another good Delphi tool is Eurekalog

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