Solved

memory leakage problem

Posted on 2001-07-14
4
159 Views
Last Modified: 2010-04-06
Ok I need to know if there is any memory leakage in this code:

procedure TfrmMain.LoadDatFile;
var MyStream: TFileStream; FavRec: PFavoriteRec;
begin
  if FileExists('linkslist.dat') then begin
     MyStream := TFileStream.Create('linkslist.dat', fmOpenReadWrite);
     New(FavRec);

     MyStream.Seek(0, soFromBeginning);
     try
        while MyStream.Read(FavRec^, SizeOf(TFavoriteRec)) = SizeOf(TFavoriteRec) do begin
           tvFavs.Items[FavRec.AbsIndex].Data := FavRec;
           tvFavs.Items[FavRec.AbsIndex].ImageIndex := 2;
           tvFavs.Items[FavRec.AbsIndex].SelectedIndex := 2;
           New(FavRec);
        end;
     finally
        MyStream.Free;
     end;
  end;
end;

I'm allocating memory for those FavRecs, but I never use Dispose. And I'm not sure that when tvFavs (TreeView) is freed the .Data pointer is also freed.

many thanks.
0
Comment
Question by:pin_plunder
  • 3
4 Comments
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
You have to free it yourself...
0
 

Author Comment

by:pin_plunder
Comment Utility
you mean, before closing my app something like this should execute:

Dispose(tvFavs.Items[i].Data)

thanks


0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
Wll, when you close your app it will be freed. In fact all memory allocated with e.g. New or Allocmem, will be released automatically. But when you remove a treenode, you have to call Dispose to release the memory.
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 50 total points
Comment Utility
I mean that when you don't free the memory when you remove a treenode, it will not be released until you close your app.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now