Memory leak

General TRichView support forum. Please post your questions here
Post Reply
leeand
Posts: 2
Joined: Wed Jul 18, 2007 12:29 am

Memory leak

Post by leeand »

From a beginners point:
I have difficulties with access errors and memory leaks when closing application with TRV (ver9) + table + dynamic generated images.

Images are created on demand like:
Timage(picarray):=Timage.create ....
picarray.loadfromfile(filelist).....
table.cells[x,y].addpicturex(picarray,......)
printthisRVdocument()
rv.rvdata.clear; //should delete all items and free memory
setlength(picarray,0);

Now, when closing the application memcheck will show a lot of errors. They disappear of I do not generate rv documents. Any ideas how to make this water proof and exclude memory leak errors?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You call AddPictureEx(... picarray.Picture.Graphic, ...)
TRichView will delete picarray.Picture.Graphic, but picarray will not be deleted.

Is it necessary to create array of TImages?
For example, you can use grarray: array of TGraphic instead of picarray.

So the code will be

Code: Select all

var pic: TPicture;

pic := TPicture.Create;
pic.LoadFromFile(filelist[i]);
grarray[i] := RV_CreateGraphics(TGraphicClass(pic.Graphic.ClassType));
grarray[i].Assign(pic.Graphic);
pic.Free;
table.cells[x,y].addpicturex(grarray[i],......) 
printthisRVdocument() 
rv.Clear; 
setlength(grarray,0); 
This is about memory leaks. As for AV errors, may be you add the same picture more than one time, so it is freed several time?
leeand
Posts: 2
Joined: Wed Jul 18, 2007 12:29 am

memory leaking

Post by leeand »

TRichView will delete picarray.Picture.Graphic, but picarray will not be deleted.


Yes, I think this can be the cause of my problem!

This is about memory leaks. As for AV errors, may be you add the same picture more than one time, so it is freed several time?


Such mistakes - I found - are easier to trace and to correct than memory leak errors.
Great support, great component!
Post Reply