Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/RTL/Delphi/Other RTL    [ Add a report in this area ]  
Report #:  67690   Status: Closed
TInterfaceList memory leak
Project:  Delphi Build #:  12.0.3155.16733
Version:    12.0 Submitted By:   Alexey Kazantsev
Report Type:  Basic functionality failure Date Reported:  10/8/2008 8:57:43 PM
Severity:    Infrequently encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   266120
Resolution: As Designed (Resolution Comments) Resolved in Build: : 14.0.3439.21621
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
Memory leak in TInterfaceList
Steps to Reproduce:
ReportMemoryLeaksOnShutdown := True;

With TInterfaceList.Create Do
  Try

   Add(TInterfacedObject.Create);
   Add(TInterfacedObject.Create);
   Add(TInterfacedObject.Create);

   // Clear list without memory realloc (leak here)
   Count := 0;

  Finally

   Free;

  End;
Workarounds
None
Attachment
None
Comments

Tomohiro Takahashi at 10/9/2008 4:57:32 AM -
I do not why Count property is writable.
Please try to use Clear method instead of Count := 0;
When we set Count property, please be careful.

Alexey Kazantsev at 10/9/2008 11:13:15 PM -
Count property writable for clearing list without memory realloc for internal buffer. It's normal practice for TList.

Lucian Radulescu at 10/13/2008 7:07:18 AM -
>It's normal practice for TList.

No, it is not normal practice. Normal is to use Clear.
Also, as Tomohiro said, I don't know why Count is writeable.

Alexey Kazantsev at 10/13/2008 10:17:39 PM -
No, it is normal proctice :)

See help:

"Increasing the size of Count will add the necessary number of nil (Delphi) or NULL (C++) pointers to the end of the Items array. Decreasing the size of Count will remove the necessary number of entries from the end of the Items array."

See pseudocode:

list := TList.Create;
Try

  Repeat

   fillList(list); // get items
   processList(list); // process items

   {
   list.clear; // clear with memory reallocation (on each iteration!!!)

   or

   list.Count := 0; // clear without memory reallocation (quickly and efficient)
   }

  Until _reason_;

Finally

  list.Free;

End;

Lucian Radulescu at 1/20/2009 1:38:09 PM -
>Alexey Kazantsev said - "No, it is normal proctice :)
>See help:

If something is said in the helpfile, that doesn't necesarily makes it normal practice. I don't think I've seen List.Count := 0 in my career, but than probably the teams I've worked with thought like me :-)

Alexey Kazantsev at 2/1/2009 3:54:52 PM -
Count := 0 is private case of decrease of count.

Server Response from: ETNACODE01