Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Class, records and memory leaks (https://www.delphipraxis.net/172795-class-records-memory-leaks.html)

WojTec 23. Jan 2013 11:15

Delphi-Version: 2010

Class, records and memory leaks
 
I just bought EL7 and checked project with it. It found some memory leaks (I thought that TListView.TListItem.Data can be free automatically, but ok, I did it manually). But I have yet another leak and I don't know WTF :cyclops:

So, I'm adding to TListView simple class with 2 reintroduced constructors and a few record field (some record fields has another record field). On object create I only need to alloc memory and init one field (fill record with valid data) - parameter in one constructor. This record has 2 string fields and for next operations in proggy it have to valid values. To make sure record contain valid data I'm filtering input by function - it sets valid values in record, then function result is passed as constructor parameter (and second constructor doing the same, but itself internally). All is oke, hmm, it isn't oke - at the program termination EL reporting memory leaks in function that setting valid data for constructor. All in pseudocode:

Code:
button click:
 AddItem(TObj.Create(foonction(input1, input2: str))) // <-- point 1

foonction(param1, param2: str): record;
 result.param1 := extractdata1()
 result.param2 := extractdata2()

 result := formatit(result) // <-- point 2

formatit (record): record;
 do format fields strings

point 3 in EL log is in System._NewUnicodeString
:roll::?:

Sir Rufo 23. Jan 2013 13:45

AW: Class, records and memory leaks
 
Alister Christie just published a new Video Tutorial for you

http://www.delphipraxis.net/172786-m...itemclass.html

Do you really think your pseudo code will give us a clue about the leaks? :roll:

WojTec 23. Jan 2013 14:28

Re: Class, records and memory leaks
 
Zitat:

The OnCreateItemClass event was introduced to TListView a few versions of Delphi ago, you've probably never noticed it (...)
Yes, that's true :lol:

About leaks - now I'm not sure if any are in my proggy. EL6 and EL7 in v6 mode doesn't show any, but EL7 after disable backward compatibility reporting a few kB leaked... I don't know...

Union 23. Jan 2013 15:03

AW: Class, records and memory leaks
 
Try to disable EL and verify the leaks with FastMM.


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:35 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz