Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

memory leakage problem

Posted on 2001-07-14
4
162 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

791 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