Solved

memory leakage problem

Posted on 2001-07-14
4
166 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
[X]
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
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

623 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