If you include Forms and SvcMgr (Service classes) in the same project (in any sub unit) you may get a memory leak. It happens only if you call the Free method directly.


To make it work, you have to check for a side effect that I describe here.

The memory leak results from the SvcMgr.TServiceApplication.Destroy destructor which uses the global instance Forms.Application. In detail, it creates a memory block that is maintained by a list in TApplication. If you free the TApplication instance, the internal list is also freed, but the memory block is not! As a remedy you have to free the service object first and then recreate the TApplication instance (and if you need also the TServiceApplication).

The Forms and SvcMgr units creates their objects in the initialization section of the units. So you have to play around them.

Go through your units and check if you include SvcMgr and Forms.