Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best tool to detect memory leaks in Delphi [closed]

What is the best tool to detect memory leaks.

Both free and not Free.

Thanks

like image 746
Jlouro Avatar asked Jan 06 '09 10:01

Jlouro


People also ask

How do I find a memory leak in Delphi?

You can easily integrate into RAD Studio and find memory leaks within your Delphi and C++Builder applications. Deleaker shows allocated memory, objects, handles, and GDI resources. That means you can find all the issues within your RAD Studio.

What tool is most commonly used to detect memory leaks?

Using Memory Profilers Memory profilers are tools that can monitor memory usage and help detect memory leaks in an application. Profilers can also help with analyzing how resources are allocated within an application, for example how much memory and CPU time is being used by each method.

How do you detect a memory leak?

The best approach to checking for the existence of a memory leak in your application is by looking at your RAM usage and investigating the total amount of memory been used versus the total amount available. Evidently, it is advisable to obtain snapshots of your memory's heap dump while in a production environment.

Which tool is used for handling memory leak problem in Linux?

The most popular Valgrind tool is Memcheck, a memory-error detector that can detect issues such as memory leaks, invalid memory access, uses of undefined values and problems related to allocation and deallocation of heap memory.


4 Answers

FastMM is a free (source available) memory leak detector, already integrated in the latest Delphi versions. I never had a need for anything else.

It's much better BTW to limit the possibilities of memory leaks when coding, instead of finding them later. Some tips:

Always use try and finally in your code to free created objects. Better to write this code immediately, and then write code to use the objects. Even better to make use of IDE functionality like Code Templates.

Only use functions that return dynamically allocated objects when absolutely necessary. It's generally better to pass objects as parameters than create and return them. For example this

procedure getChoices(var AChoices: TStrings);

would be much better than

function getChoices: TStrings;

as there is no potential of accidently leaking the created TStrings object.

like image 181
mghie Avatar answered Oct 13 '22 12:10

mghie


We use EurekaLog at our work in Delphi 7. It's an exception handler component which gives very detailed information about exceptions (including callstack! environment variables, etc) even for access violations. But another great feature is that you can tell it to error on memory leaks too, which shows the exact line of code where the memory/object was allocated in the first place! It is a commerical product but I would still highly recommend it.

like image 38
CodeAndCats Avatar answered Oct 13 '22 12:10

CodeAndCats


AQTime is very good. It also does other things like profiling for performance. And it does not require any changes in your code. Of course compiling with debug info helps giving better results.

like image 34
Lars Truijens Avatar answered Oct 13 '22 12:10

Lars Truijens


I would recommend the full FastMM4-version over the version included in Delphi. The full version gives you a full and verbose report logged to file instead of the dialogbox. Combine this with a homebrewed 'memoryleak-logfile-differ' your're all set for an exiting bughunt.

like image 30
Vegar Avatar answered Oct 13 '22 12:10

Vegar