mjn
mjn

Reputation: 36644

How can I use FastMM4 memory leak reporting in a Service?

Does the same technique which FastMM4 for Delphi provides to report memory leaks to a detailed file work if the application runs as service? Of course the best practice would be to write unit tests and a simple standalone application first, and find the leaks there, outside the service environment.

Upvotes: 3

Views: 3718

Answers (5)

Niko
Niko

Reputation: 79

  1. Do the instructions as described in the readme file for FastMM
  2. Enable {.$define NoMessageBoxes} in FastMM4Options.inc File
  3. Disable {$define RequireDebuggerPresenceForLeakReporting} in FastMM4Options.inc File
  4. Install/Start Service and after stopping it you will get MyApp_MemoryManager_EventLog File in output folder.

Upvotes: 0

Marc
Marc

Reputation:

Ok I found out another reason why sometimes you cannot see any output, logfile or messagebox......

If you do not make any error, it does not create any output.

So to test if FASTMM478 works deliberately make an error in your program like:

//Create and to NOT destroy testToMakeError := TStringList.Create; for I := 0 to 100 do testToMakeError.Add('foobar');

I just presumed I would have made some error somewhere and spend a day trying to find out why the program did not gave me any feedback.

Marc

Upvotes: 0

Marc
Marc

Reputation:

I am having the same challenge at the moment. I tried this, but it does not work, at least so far for me. There are sufficient rights for the account, since the service can write his own proprietary logfile. I have switched on FullDebugMode and added the dll, I have switched on LogMemoryLeakDetailToFile, both via the IDE options. In the code I see that the right areas are seen by the compiler, when I provoke an error for example, the compiler reports it. Also I cannot debug the FastMM code. If I put a breakpoint it is ignored. I have searched all my local hard disks where that report might be gone to, it is not to be found. I start and stop the service from 'Administration-Services', all goes well, it starts up, but no report. If I do the same with a normal executable, all goes well. I am using FastMM478, and Delphi2007.

Marc

Upvotes: 0

David Taylor
David Taylor

Reputation: 2051

As Lars Truijens notes, writing to a log file requires file system privileges. The default Local System account (i.e. when you do not set an account explicitly or logon in your code) has full access to the local file system but has no default network access.

FWIW - I typically develop my services as regular Windows apps until the main part of the logic is up and running and stable. Using a library like SvCom allows you to run your services as a regular desktop application or as a service without any code changes.

Upvotes: 4

Lars Truijens
Lars Truijens

Reputation: 43595

Yes, provided the account used to running the service has enough rights to write the log file.

Upvotes: 2

Related Questions