EurekaLog newsgroups
Go Back   EurekaLog newsgroups > Support > General
Reply
 
Thread Tools Display Modes
  #1  
Old 29-Oct-2011, 12:24 AM
Ann Lynnworth
Guest
 
Posts: n/a
Default how to register expected memory leak

Hi, Is there some way to register an expected memory leak, so that it
is not reported when my program exits?

This is regarding unit CSIdStack which is part of Indy and used in
CodeSite 4.62 and Code Express 5 (e.g. with Delphi XE, XE2).  This is the code from the end of the unit: finalization   // Dont Free. If shutdown is from another Init section, it can cause GPF when stack   // tries to access it. App will kill it off anyways, so just let it leak   {$IFDEF FREE_ON_FINAL}   FreeAndNil(GStackCriticalSection);
  {$ENDIF}

To see the problem, make a new Delphi VCL project, add the unit CodeSiteLogging, activate EurekaLog and turn on reporting of memory leaks.  Run the program and exit.  EurekaLog always reports one 32-byte memory leak of TCSIdCriticalSection.  You should be able to reproduce this with CodeSite Express v5 which is included with Delphi XE2.

Thank you.

-Ann

Reply With Quote
  #2  
Old 31-Oct-2011, 10:25 AM
Alex Alex is offline
Support Team
 
Join Date: Jan 2009
Location: Russia
Posts: 1,386
Send a message via ICQ to Alex
Default

Hi,

EurekaLog 6 doesn't have any pre-defined RegisterExpectedLeak-like function, but you can do this by using such code:

uses
  ELeaks;

var
  EurekaLogAddLeak: procedure(const LeakType: AnsiString; LeakSize, LeakCount: DWord; LeakCallStack: TRawCallStack);

procedure Internal_AddLeak(const LeakType: AnsiString; LeakSize, LeakCount: DWord; LeakCallStack: TRawCallStack);
begin
  if { this is unwanted leak } then
    Exit;
  EurekaLogAddLeak(LeakType, LeakSize, LeakCount, LeakCallStack);
end;

initialization
  EurekaLogAddLeak := AddLeak;
  AddLeak := My_Internal_AddLeak;
end.
__________________
Best regards...

Alexander - EurekaLog Developer Team
Reply With Quote
  #3  
Old 07-Mar-2012, 06:44 PM
piotr.rezmer@ens.net.pl piotr.rezmer@ens.net.pl is offline
Member
 
Join Date: Aug 2005
Posts: 34
Default Where to store leak registrations

Hello,

I want to implement registration of memory leaks, and then checking arguments of internal_AddLeak() procedure if there is corresponding leak registered. I tried 2 approaches:

A) Storing leak registration inside

implementation

var leakArray : array of TLeakRegistration, 
where TleakRegistration is a class


B) Storing leak registration in var leaks: TObjectDictionary<string, TLeakRegistration>

Problems:
When using A) approach, leakArray is already empty (length = 0) when internal_addLeak procedure is called.
When using B) approach, leaks collection is not empty, but it creates internal memory leak.
__________________
best regards
Piotr Rezmer
Reply With Quote
  #4  
Old 16-Mar-2012, 09:16 AM
Alex Alex is offline
Support Team
 
Join Date: Jan 2009
Location: Russia
Posts: 1,386
Send a message via ICQ to Alex
Default

Hi,

Dynamic arrays are auto-management type. It's finalized when it's out of scope. In case of global variable - when finalization section is executed. Probably, your unit is finalized before EurekaLog.

You have 2 options:
1. Use static array, allocated dynamically via pointer. You'll have to control memory manually, which will prevent it from being finalized at unappropriate time.

2. Create a special unit to hold array. Place it before any other units in uses of dpr. Note, that this is very dangerous way. I don't recommend to do this, unless you really understand what you're doing and internals of RTL initialization/finalization chain.
__________________
Best regards...

Alexander - EurekaLog Developer Team
Reply With Quote
Reply

Tags
memory leaks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 10:11 PM.
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © EurekaLab s.a.s. - VAT ID: IT05554520824