delphimemory-leaksfastmmrad-server

How to debug a memory leak in BPL file used in Embarcadero Rad Server running in Apache in Windows


I need help locating a memory leak in an endpoint resource file used in Rad Server running in Apache on Windows. I believe FastMM is built in to Delphi 10.3 (which I am using), but I am unsure how to enable it or even how to get the output from it. All the instructions I could find say to include ReportMemoryLeaksOnShutdown := true in the begin section of the DPR, but since this is just a BPL file, I'm not sure where it goes. Also, it appears that a dialog is displayed when the application is closed, but since this is running in Apache, where would the data be?

Is there some other tool I could/should use instead of FastMM?

Any help would be appreciated and if I am missing any important info in my question, please let me know. Thank you.


Solution

  • We use the downloaded version of FastMM . You need to add the FastMM unit as first included unit. In addition make sure that the FastMM Debug dll is in the apache folder.

    You can then change the FastMM.inc file such that it refletcs your needs. We use the following settings (based on the original file but stripped from comments...) - of course you can change the settings here e.g. maybe the option "UseRuntimePackages" is needed in your case:

    {$Message Warn 'Debug memory manager configuration. Do not use in production'}
    
    {$define Align16Bytes}
    {$define UseCustomFixedSizeMoveRoutines}
    {$define UseCustomVariableSizeMoveRoutines}
    {.$define InstallOnlyIfRunningInIDE}
    {.$define NeverUninstall}
    {.$define UseRuntimePackages}
    {$define AssumeMultiThreaded}
    {.$define NeverSleepOnThreadContention}
    {.$define UseSwitchToThread}
    {.$define NoDebugInfo}
    {$define NoMessageBoxes}
    {$define UseOutputDebugString}
    {$define ASMVersion}
    {$define CheckHeapForCorruption}
    {$define DetectMMOperationsAfterUninstall}
    {$define FullDebugMode}
      {$define RawStackTraces}
      {$define CatchUseOfFreedInterfaces}
      {$define LogErrorsToFile}
      {$define LogMemoryLeakDetailToFile}
      {$define ClearLogFileOnStartup}
      {.$define LoadDebugDLLDynamically}
        {.$define DoNotInstallIfDLLMissing}
      {$define AlwaysAllocateTopDown}
      {.$define DisableLoggingOfMemoryDumps}
      {$define SuppressFreeMemErrorsInsideException}
      {.$define FullDebugModeCallBacks}
    
    {$define EnableMemoryLeakReporting}
    
      {$define HideExpectedLeaksRegisteredByPointer}
      {.$define RequireIDEPresenceForLeakReporting}
      {$define RequireDebugInfoForLeakReporting}
      {.$define ManualLeakReportingControl}
      {.$define HideMemoryLeakHintMessage}
    {.$define EnableMMX}
      {$define ForceMMX}
    {$define ShareMM}
      {$define ShareMMIfLibrary}
    {$define AttemptToUseSharedMM}
    {.$define ClearMemoryBeforeReturningToOS}
    {.$define AlwaysClearFreedMemory}
    {.$define LogLockContention}
    {.$define FullDebugModeInIDE}
    {.$define FullDebugModeWhenDLLAvailable}
    {$ifdef Release}
      {Specify the options you use for release versions below}
      {.$undef FullDebugMode}
      {.$undef CheckHeapForCorruption}
      {.$define ASMVersion}
      {.$undef EnableMemoryLeakReporting}
      {.$undef UseOutputDebugString}
    {$else}
      {Specify the options you use for debugging below}
      {.$define FullDebugMode}
      {.$define EnableMemoryLeakReporting}
      {.$define UseOutputDebugString}
    {$endif}
    
    {.$define borlndmmdll}
    {.$define dllforide}
    {.$define debugdll}
    {$ifdef borlndmmdll}
      {$define AssumeMultiThreaded}
      {$undef HideExpectedLeaksRegisteredByPointer}
      {$undef RequireDebuggerPresenceForLeakReporting}
      {$undef RequireDebugInfoForLeakReporting}
      {$define DetectMMOperationsAfterUninstall}
      {$undef ManualLeakReportingControl}
      {$undef ShareMM}
      {$undef AttemptToUseSharedMM}
      {$ifdef dllforide}
        {$define NeverUninstall}
        {$define HideMemoryLeakHintMessage}
        {$undef RequireIDEPresenceForLeakReporting}
        {$ifndef debugdll}
          {$undef EnableMemoryLeakReporting}
        {$endif}
      {$else}
        {$define EnableMemoryLeakReporting}
        {$undef NeverUninstall}
        {$undef HideMemoryLeakHintMessage}
        {$define RequireIDEPresenceForLeakReporting}
      {$endif}
      {$ifdef debugdll}
        {$define FullDebugMode}
        {$define RawStackTraces}
        {$undef CatchUseOfFreedInterfaces}
        {$define LogErrorsToFile}
        {$define LogMemoryLeakDetailToFile}
        {$undef ClearLogFileOnStartup}
      {$else}
        {$undef FullDebugMode}
      {$endif}
    {$endif}
    
    {$ifdef BCB}
      {$ifdef CheckHeapForCorruption}
        {$define PatchBCBTerminate}
      {$else}
        {$ifdef DetectMMOperationsAfterUninstall}
          {$define PatchBCBTerminate}
        {$else}
           {$ifdef EnableMemoryLeakReporting}
             {$define PatchBCBTerminate}
           {$endif}
        {$endif}
      {$endif}
    
      {$ifdef PatchBCBTerminate}
        {$define CheckCppObjectType}
        {$undef CheckCppObjectTypeEnabled}
    
        {$ifdef CheckCppObjectType}
          {$define CheckCppObjectTypeEnabled}
        {$endif}
    
        {Turn off "CheckCppObjectTypeEnabled" option if neither "CheckHeapForCorruption"
         option or "EnableMemoryLeakReporting" option were defined.}
        {$ifdef CheckHeapForCorruption}
        {$else}
          {$ifdef EnableMemoryLeakReporting}
          {$else}
            {$undef CheckCppObjectTypeEnabled}
          {$endif}
        {$endif}
      {$endif}
    {$endif}