Memory leak in TDBRichView

General TRichView support forum. Please post your questions here
Post Reply
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Memory leak in TDBRichView

Post by PioPio »

Hello,

I have the following code:

Code: Select all

unit Unit1;

interface

uses
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Variants,
  System.Classes,
  Vcl.Graphics,
  rvstyle,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  RVScroll,
  RichView,
  RVEdit,
  DBRV;

type
  TForm1 = class(TForm)
    procedure FormActivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    FForm: TForm;
    FRVStyle: TRVStyle;
    FDBRichViewEdit: TDBRichView;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormActivate(Sender: TObject);
begin
  FRVStyle := TRVStyle.Create(nil);
  FDBRichViewEdit := TDBRichView.Create(nil);
  FDBRichViewEdit.Parent := Self;
  FDBRichViewEdit.Style := FRVStyle;
  FDBRichViewEdit.Visible := True;

end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  FRVStyle.Free;
  FDBRichViewEdit.Free;
end;
The application compiles and runs regularly but MadExcept http://madshi.net/madExceptDescription.htm detects a problem when I close the application. The following is the report:

end.allocation number: 1932
program up time: 1.22 s
type: OpenThemeData
address: $b0002
access rights: ./.

main thread ($1fa8):
671d409a madExcept32.dll madExceptDbg 5504 OpenThemeDataCallback
006eb314 Project2.exe RVScroll 1289 TRVScroller.CreateThemeHandle
006e9acd Project2.exe RVScroll 499 TRVScroller.CreateWnd
00514fbe Project2.exe Vcl.Controls TWinControl.CreateHandle
00515288 Project2.exe Vcl.Controls TWinControl.UpdateShowing
005152b6 Project2.exe Vcl.Controls TWinControl.UpdateShowing
00515430 Project2.exe Vcl.Controls TWinControl.UpdateControlState
00514682 Project2.exe Vcl.Controls TWinControl.InsertControl
0050fba8 Project2.exe Vcl.Controls TControl.SetParent
0051ae9d Project2.exe Vcl.Controls TWinControl.SetParent
0074ff98 Project2.exe Unit1 45 TForm1.FormActivate
00591c27 Project2.exe Vcl.Forms TCustomForm.Activate
00592ce8 Project2.exe Vcl.Forms TCustomForm.CMActivate
005115c5 Project2.exe Vcl.Controls TControl.WndProc
00515f23 Project2.exe Vcl.Controls TWinControl.WndProc
0058f24d Project2.exe Vcl.Forms TCustomForm.WndProc
00515578 Project2.exe Vcl.Controls TWinControl.MainWndProc
00489538 Project2.exe System.Classes StdWndProc
7650558d USER32.dll SendMessageW
0058c12c Project2.exe Vcl.Forms SendFocusMessage
00515b27 Project2.exe Vcl.Controls TWinControl.WndProc
0058f24d Project2.exe Vcl.Forms TCustomForm.WndProc
00515578 Project2.exe Vcl.Controls TWinControl.MainWndProc
00489538 Project2.exe System.Classes StdWndProc
7794700b ntdll.dll KiUserCallbackDispatcher
00515f23 Project2.exe Vcl.Controls TWinControl.WndProc
0058f24d Project2.exe Vcl.Forms TCustomForm.WndProc
00515578 Project2.exe Vcl.Controls TWinControl.MainWndProc
00489538 Project2.exe System.Classes StdWndProc
7794700b ntdll.dll KiUserCallbackDispatcher
005115c5 Project2.exe Vcl.Controls TControl.WndProc
00515f23 Project2.exe Vcl.Controls TWinControl.WndProc
0058f24d Project2.exe Vcl.Forms TCustomForm.WndProc
00511200 Project2.exe Vcl.Controls TControl.Perform
00515321 Project2.exe Vcl.Controls TWinControl.UpdateShowing
00515430 Project2.exe Vcl.Controls TWinControl.UpdateControlState
0051803e Project2.exe Vcl.Controls TWinControl.CMVisibleChanged
00515f23 Project2.exe Vcl.Controls TWinControl.WndProc
0058f24d Project2.exe Vcl.Forms TCustomForm.WndProc
00511200 Project2.exe Vcl.Controls TControl.Perform
0050fbde Project2.exe Vcl.Controls TControl.SetVisible
00759a49 Project2.exe Project2 18 initialization
7645ef1a kernel32.dll BaseThreadInitThunk
It seems the issue is generated by the line

Code: Select all

FDBRichViewEdit.Parent := Self; 
because if I comment it out I have no warnings but in this case some operations cannot be performed by TDBRichViewEdit. How can I solve the issue ?


Many thanks
Alberto
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Post by PioPio »

It turned out that if I set

Code: Select all

FNiftyDBRichViewEdit.UseXPThemes:=False;
then I have no warning memory leak notification messages from MadExcept.

Why is it ? Is there any way to keep UseXPThemes=True without having memory leaks ?

Many thanks
Alberto
Sergey Tkachenko
Site Admin
Posts: 17534
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please tell me versions of TRichView, madExcept and Delphi.

I tried your code with the newest version of TRichView (however, no changes related to theme handles were made for a very long time), Delphi 10, MadExcept 4.0.13.
MadExcept reported no leaks.
Sergey Tkachenko
Site Admin
Posts: 17534
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You can put breakpoints in
TRVScroller.CreateThemeHandle
and
TRVScroller.FreeThemeHandle
You will see that TRVScroller.CreateThemeHandle is called when you assign Parent, and TRVScroller.FreeThemeHandle is called when you close the form.
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Post by PioPio »

Sergey Tkachenko wrote:Please tell me versions of TRichView, madExcept and Delphi.

I tried your code with the newest version of TRichView (however, no changes related to theme handles were made for a very long time), Delphi 10, MadExcept 4.0.13.
MadExcept reported no leaks.
I have:
TRichView 15
madExcept 4.0.14
Delphi XE 2
Sergey Tkachenko
Site Admin
Posts: 17534
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I upgraded madExcept to 4.0.14 and tried this project in XE2.
madExcept still does not report any leaks with the latest version of TRichView.
I am quite sure that nothing was changed related to theme handle allocation and de-allocation since TRichView v15.0.

Did you try breakpoints as I suggested?

I tested in Windows 8.1
Post Reply