Page 1 of 1

Memory leak

Posted: Wed Jul 18, 2007 12:44 am
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?

Posted: Wed Jul 18, 2007 6:52 am
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?

memory leaking

Posted: Wed Jul 18, 2007 1:22 pm
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!