Root > How to... > ...ignore/hide a leak?

...ignore/hide a leak?

Previous pageReturn to chapter overviewNext page   

First, you have to identify memory or resource leak which you want to ignore. You can identify leak by:

Exact variable;
Leak type (data, string, array, object, etc.);
Leak location;
Leak size;
Other information.

 

Once leak is identified - you can instruct EurekaLog to ignore this leak. There are few available methods. Not all methods supports all of the features discussed above. This article covers the following options:

1. Register known leak
2. Use event handlers

 

Important note: you can not use exception filters to ignore leaks, because leaks checking is performed as last step on shutdown - when all exception filters were already finalized.

 

See also:

 

 

Option 1

Register a known memory leak.

 

EMemLeaks unit contains EurekaRegisterExpectedMemoryLeak, EurekaRegisterExpectedMemoryLeakDynArray, and EurekaRegisterExpectedMemoryLeakStr routines, which you may use to instruct EurekaLog to ignore leak of known location (variable). For example:

 

EurekaRegisterExpectedMemoryLeak(RogueUnit.RogueVariable);
EurekaRegisterExpectedMemoryLeak(Pointer(RogueUnit.RogueObject));
EurekaRegisterExpectedMemoryLeakDynArray(Pointer(RogueUnit.RogueDynamicArray));
EurekaRegisterExpectedMemoryLeakStr(Pointer(RogueUnit.RogueString));

 

This can only work if you have access to the data which will be leaked.

 

Important note: be sure to register known leaks as late as possible - preferably on shutdown. This is to avoid cases when leaked variable may change its address due to re-allocating during normal work at run-time.

 

 

Option 2

Use event handlers.

 

EMemLeaks unit uses global MemLeaksAdd procedure (actually declared in ETypes unit), which is assigned to default handler. You may assign your own handler to this variable. Similarly, EResLeaks unit uses ResLeaksAdd routine. For example:

 

var
  AddLeak: TMemLeaksAdd;
 
function FilterLeaks(const AMemBlock: Pointer; const ABlockType: TBlockType;
                     const LeakDescription: String;
                     const LeakSingleSize, LeakTotalSize, LeakCount: PtrUInt;
                     const LeakCallStack: TCallStackArray): Boolean;

 
  function IgnoreThisLeak: Boolean;
  begin
    // This is only an example, replace with your own code
    Result := (ABlockType = btObject) and
              (TObject(AMemBlock) is TMyObject) and
              (LeakSingleSize = 64);
  end;
 
begin
  if IgnoreThisLeak then
  begin
    // Return True if leak was added, False otherwise
    Result := False;
    Exit;
  end;
 

  // Call default/previous handler to add leak 
  Result := AddLeak(AMemBlock, ABlockType, LeakDescription,
          LeakSingleSize, LeakTotalSize, LeakCount,
          LeakCallStack);
end;
 
initialization
finalization
  AddLeak := MemLeaksAdd;
  MemLeaksAdd := FilterLeaks;
end.

 

 

See also:




Send feedback... Build date: 2024-09-30
Last edited: 2023-03-07
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/how_to_ignore_leak.php