Solved

memory leakage problem

Posted on 2001-07-14
4
161 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
ID: 6282443
You have to free it yourself...
0
 

Author Comment

by:pin_plunder
ID: 6282617
you mean, before closing my app something like this should execute:

Dispose(tvFavs.Items[i].Data)

thanks


0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6282623
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
ID: 6282636
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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