FAQ

Can Leak Browser help find COM object leaks?

COM objects are not specifically tracked. Most COM objects use memory, and that memory must be allocated. Since Leak Browser tracks memory allocations it will track COM objects that use any of the memory allocators that are tracked. Most COM leaks are due to either bad reference counting (forgetting to call Release) or cyclic references. Once you have used Leak Browser to find the COM object that is leaked you will usually need to manually work out which client has forgotten to call Release.

How much does Leak Browser impact performance?

How long is a piece of string?

If your program does nothing but call new and delete then Leak Browser will have a huge amount of work to do. However, Leak Browser is highly optimized so that the performance impact on most program is hard to spot. Leak Browser was originally written to target machines with Pentium II processors running at about 266MHz, so with more modern processors and several years of refining Leak Browser’s source code performance is not normally a problem.

Can Leak Browser monitor remote processes?

Yes. However, since Windows NT4 Microsoft have made efforts to secure Windows, now various services that are required are typically not available.

The recommendation is to install locally rather than waste time trying to configure machines for remote debugging.

You must be an administrator of the remote machine, and an ADMIN$ share must exist on the remote machine. The ADMIN$ share is a standard hidden share that windows uses to expose the windows directory to the network. This also implies that the server services must be enabled, and permitted on the firewall. Also remote registry access must be permitted, this implies the remote registry service is running and the RPC locator service.

Can Leak Browser monitor multiple processes?

Yes. Just attach to the processes you want to monitor (one at a time), and then use the MDI interface to switch between the windows for each process. You can run multiple copies of Leak Browser, but this will take more memory.

Can I avoid leaks by using garbage collection?

No. You can reduce the amount of leaks using garbage collection, how much is very variable. Leak Browser was initially written to identify leaks in a project where one of the world’s leading garbage collectors had failed badly (it found less than 1% of the leaks). The key problems with garbage collection are:

  • Most garbage collectors do not track all allocations. For example new/delete may be tracked but not native system calls.
  • An unintended reference to an object will defeat a garbage collector.
  • There are also the issues concerning the cost of garbage collection.

Typically garbage collectors are concerned with calls to new, delete, malloc, free, etc., but we have found that this is not where most leaks occur. What about all those operating system calls like SysAllocString, or CreateEvent? Do you always remember to call SysFreeString or CloseHandle? Do you always use smart objects to encapsulate access to these operating system object? The problems mostly occurs because the Win32 exposes most of its APIs with a “C” interface. This is not very suitable for either C++ or Visual Basic, indeed it is only really suitable for “C”, and it is at the “language interface” boundaries that most programmers make mistakes. What is needed is a native language wrapper on top of the “C” interface. This is part of what the .NET framework attempts to do (how well remains to be seen).

If you write code in 100% portable C/C++ and thus don’t make operating system calls directly, and if you do not use multiple languages, then a garbage collector may be right for you.

There are a number of times that we have found objects being added to collections but never removed until application shutdown. This results in the collection growing and growing, until the application is eventually shutdown (probably because it is out of memory). To a garbage collector this is not a leak because all objects are still reachable. To your customer it is a leak, because the application eventually slows down and/or crashes.

If you are using a garbage collected language e.g. Java, then your code may not leak, but if the virtual machine implementation leaks, then your customers are no better off. (Most of the leaks in Netscape Communicator come from the Java virtual machine.)

Does Leak Browser support .NET?

This is not to be confused with “Does Leak Browser support Visual Studio .NET?”. Leak Browser does not support the Microsoft .NET managed applications, and it is not likely to do so in the near future. There are plenty of other debuggers that are able to help you find leaks in .NET managed applications. The .NET framework makes this relatively easy when compared with tracking leaks in native code, thus those other debuggers are likely to yield good results. Sufficient support to deal with mixed code unmanaged code in a managed environment.

Can you add support for XXX?

If you have a particular need but Leak Browser does not quite fit, then please contact me. If may be possible to provide you with a custom build of Leak Browser or to add more generalized support.

For example, I may be interested in adding support for Python.

Leak Browser can easily track custom resources within your application without any change. To do this either call Leak Browser’s API (exposed via LeakBrowserStub.dll) or associate a resource that is tracked by Leak Browser with your custom resource for example by making it a member variable.

Does Leak Browser support Scripting?

No scripting clients are not supported. Only directly compiled clients are supported. If you use Leak Browser in a scripted environment you will see stack traces into the script interpreter. There is no way to identify which line of script was executing (without support from every script interpreter). As a general recommendation with regard to writing robust code scripting is not recommended for significant amounts of code because it lacks so many safety features that compiled languages offer.

Does Leak Browser support garbage collection

In theory your are able to force a garbage collection before requesting that Leak Browser generates a report then it should work. Leak Browser has been successfully on software that uses garbage collection, indeed MSXML uses a garbage collector. The problem is no with garbage collection but with heap compaction. If memory blocks are moved then Leak Browser may falsely attribute an allocation to the heap compactor rather than to the code that originally made the allocation.

Does Leak Browser support Java?

Java is not supported. However, if the Java code is compiled to a native .exe or .dll rather than being interpreted, it may work, however, the garbage collector is likely to get in the way. See FAQ about garbage collection.

Does Leak Browser work with languages other than C/C++

Leak Browser will work with any compiled code on the Win32 target platform for which symbol files are available. However, Leak Browser has special knowledge about C and C++ so it works best with these. Any system that moves blocks of memory around is also likely to confuse Leak Browser, for example a heap compactor.

Do I need to re-compile my code to use Leak Browser?

Maybe, but probably not.

You must provide symbol files. It is also advisable (but not a requirement) to use a non-optimized build. You can use a “Debug build” if you like, however, it is often better to create a “Release build” with the optimizer turned off, because this is closer to how your code will run in the field and you won’t need to install special debug DLLs. Also it is preferred to use the the DLL versions of the C/C++ runtime library. You should do this for as much code as you can. Obviously you cannot recompile third-party components, the more components that you can recompile with these settings the better.

The following will give the best results:

  • Provide .PDB files for as many components as possible. This is the only essential item.
  • Build unoptimized (but release is okay) when possible.
  • Build with exception frames enabled /GX on VC6 and prior. /EHa on Visual Studio .NET 2003 and later. The exception frames can be used to aid stack tracing.
  • If you must enable the optimizer then it is helpful build with “frame pointer omission” disabled /Oy-
  • Use the dynamic link CRT. The static link CRT is okay, but dynamic link is preferred.

Where is the FAQ?

HERE!
Well, this is not such a silly question, because there are also some FAQs in the help. However, the help is currently very out of date, so the best place is here.

Comments are closed.