Memory leak?

General TRichView support forum. Please post your questions here
Post Reply
Adz
Posts: 4
Joined: Fri Apr 08, 2016 10:07 am

Memory leak?

Post by Adz »

RVE: v14.0.3
Delphi Seattle 10 U1

Adding image to TRichViewEdit and freeing the img when closing the form throws AV.

Sample code:

Code: Select all

rve: TRichViewEdit;
img: TWICImage;
...

procedure TForm1.FormCreate(Sender: TObject);
begin
  img := TWICImage.Create;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  //rve.Clear;
  img.Free; //<-- throws av, 
end;

procedure TForm1.btnLoadPixClick(Sender: TObject);
begin
  img.LoadFromFile('image file');
  rve.AddPictureEx('', img, -1, rvvaBaseline);
  rve.Format;
end;
FastMM snippet:

Code: Select all

FastMM has detected an attempt to call a virtual method on a freed object. An access violation will now be raised in order to abort the current operation.
...

The current thread ID is 0x2864, and the stack trace (return addresses) leading to this error is:
409C2B [System.pas][System][TObject.Free$qqrv][16261]
D585E1 [RVItem.pas][RVItem][TRVGraphicItemInfo.$bdtr$qqrv][3275]
409C2B [System.pas][System][TObject.Free$qqrv][16261]
DC1023 [CRVData.pas][CRVData][TCustomRVData.InternalFreeItem$qqrp24Rvitem.TCustomRVItemInfoo][2132]
CAD86C [CRVFData.pas][CRVFData][TCustomRVFormattedData.InternalFreeItem$qqrp24Rvitem.TCustomRVItemInfoo][8483]
DC10B0 [CRVData.pas][CRVData][TCustomRVData.FreeItem$qqrio][2145]
DC1158 [CRVData.pas][CRVData][TCustomRVData.Clear$qqrv][2161]
C99247 [CRVFData.pas][CRVFData][TCustomRVFormattedData.Clear$qqrv][872]
41C964 [FastMM4.pas][FastMM4][DebugFreeMem$qqrpv][8893]
C8F1A8 [RVRVData.pas][RVRVData][TRichViewRVData.Clear$qqrv][1282]
CCDD8B [RVERVData.pas][RVERVData][TRVEditRVData.Clear$qqrv][522]
If I won't explicitly free my image instance, will rve do it for me when I close my app as I see in the log?

Thank you.
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You should not free the image inserted in TRichView, TRichView frees it itself.

(there is an option to prevent freeing this image by TRichView, you can find all the information in the help file: http://www.trichview.com/help/idh_trich ... cture.html )
Adz
Posts: 4
Joined: Fri Apr 08, 2016 10:07 am

Post by Adz »

Hi Sergey,

Thanks for the prompt reply! This confirms my log. Thank you for the support, might be here in a while, still new to trv for my client. Great support btw :)
Post Reply