Memory Leak in TRichView.OnReadHyperlink?

General TRichView support forum. Please post your questions here
Post Reply
thomasvonkapellen
Posts: 6
Joined: Wed Oct 08, 2008 8:30 am

Memory Leak in TRichView.OnReadHyperlink?

Post by thomasvonkapellen »

Hi,

in my projekt I use a TRichView-Component named "rvwEintraege_B" and fill it with a blob from a database:

Code: Select all

  blob := CreateBlobStream(qry.FieldByName('langtext'), bmRead);
  try
    blob.Seek(0, soFromBeginning);
    rvwEintraege_B.LoadRTFFromStream(blob);
  finally
    blob.Free;
 end;
To view and use the stored hyperlinks, I put the following code into then OnReadHyperlin-Event:

Code: Select all

procedure TfrmMain.rvwEintraege_BReadHyperlink(Sender: TCustomRichView;
  const Target, Extras: string; DocFormat: TRVLoadFormat; var StyleNo,
  ItemTag: Integer; var ItemName: string);
begin
  inherited;
 ItemTag := Integer(StrNew(PChar(Target)));

end;
Now I can use Hyperlinks, but the application exits with the following mermory leak (using FastMM4):
This application has leaked memory. The small block leaks are (excluding expected leaks registered by pointer):

13 - 20 bytes: Unknown x 2

Note: Memory leak detail is logged to a text file in the same folder as this application. To disable this memory leak check, undefine "EnableMemoryLeakReporting".
If I remove...

Code: Select all

ItemTag := Integer(StrNew(PChar(Target)));
... from the event, there is no the memory leak anymore.

I'm also using TDBRichViewEdit to edit the data, but here no memory leak is detected, even though I use the same code.

Any suggestions, thanks,

Tom
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Did you include rvoTagsArePChars in Option property?
If not, tags are treated like integers, and memory allocated by StrNew is not freed.
thomasvonkapellen
Posts: 6
Joined: Wed Oct 08, 2008 8:30 am

Post by thomasvonkapellen »

Ok, now I included the rvoTagsArePChars in Option property an the memory leak disappeared, but now whe I close the application I get an access violation.

Exception EAccessViolation in Modul infosys.exe bei 00010A83.

Zugriffsverletzung bei Adresse 00410A83 in Modul 'infosys.exe'. Lesen von Adresse 00000012.
After a while FastMM4 give then report below. I'll furher try to isolate the problem, but when I remove rvoTagsArePChars again, I just get the little memory leak again.

Code: Select all

---------------------------
infosys.exe: Memory Leak Detected
---------------------------
This application has leaked memory. The small block leaks are (excluding expected leaks registered by pointer):



1 - 4 bytes: TZCppCommentState x 1, TZGenericSQLQuoteState x 1, TZNumberState x 1

5 - 12 bytes: TEventDispatch x 1, TIconOptions x 1, TZGenericSQLSymbolState x 1, AnsiString x 173, Unknown x 57

13 - 20 bytes: TZSymbolRootNode x 1, TListItems x 1, TZSymbolNode x 261, TJvSelectDialogColumnStrings x 6, TRVBackground x 6, TMemoryStream x 1, TChangeLink x 19, EAccessViolation x 1, TZExecutionStack x 9, TZSQLStatement x 9, TList x 345, TZSortedList x 9, TZMinFunction x 9, TZEmptyFunction x 9, TZSUMFunction x 9, TZTimeFunction x 9, TZDefaultFunctionsList x 9, TZVariablesList x 9, TObjectList x 42, TZSoftVariantManager x 9, TZStrPosFunction x 9, TZSubStrFunction x 9, TZConcatFunction x 9, TZLowerFunction x 9, TZUpperFunction x 9, TZSqrFunction x 9, TZRoundFunction x 9, TZLog10Function x 9, TZLogFunction x 9, TZExpFunction x 9, TZTanFunction x 9, TZSinFunction x 9, TZCosFunction x 9, TZFloorFunction x 9, TZCeilFunction x 9, TZAtanFunction x 9, TZAsinFunction x 9, TZAcosFunction x 9, TZAbsFunction x 9, TZRndFunction x 9, TZPIFunction x 9, TZEFunction x 9, TZIIFFunction x 9, TZMaxFunction x 9, AnsiString x 348, Unknown x 274

21 - 28 bytes: TWorkAreas x 1, TListColumns x 1, TListBoxStrings x 4, TComboBoxStrings x 13, TRVDrawLines x 7, TColumnTitle x 64, TJvDBGridControls x 6, TJvIniLink x 6, TBookmarkList x 6, TDBGridColumns x 6, TButtonCollection x 11, TIconImage x 2, TZExpressionParser x 9, TParams x 9, TCheckConstraints x 9, TFields x 18, TMenuActionLink x 2, TPen x 159, TBrush x 268, TButtonItemActionLink x 42, AnsiString x 265, Unknown x 7

29 - 36 bytes: TButtonCategories x 8, TPadding x 109, TMargins x 143, TSizeConstraints x 143, TToolButtonActionLink x 3, TFont x 436, TZDataLink x 9, TZCollection x 9, TRVJumpInfo x 4, TFieldDef x 29, AnsiString x 107, Unknown x 40

37 - 52 bytes: TButtonGlyph x 10, TGridDataLink x 6, TButtonItem x 42, TButtonCategory x 11, TListItem x 1, TXPManifest x 1, TBitBtnActionLink x 10, TIcon x 2, TZExpression x 9, TActionBars x 2, TRVDrawLineInfo x 8, TRVTextItemInfo x 17, AnsiString x 50, Unknown x 13

53 - 68 bytes: TSubItems x 1, TTimer x 2, TFieldDefs x 9, TMasterDataLink x 9, TColumn x 64, TStringList x 54, TBitmap x 40, AnsiString x 10, Unknown x 16

69 - 84 bytes: TZSQLStrings x 9, TFieldList x 9, TFieldDefList x 9, AnsiString x 4, Unknown x 3

85 - 100 bytes: TDataSource x 9, TBitmapCanvas x 32, TControlCanvas x 117, TCanvas x 10, AnsiString x 3, Unknown x 3

101 - 116 bytes: TBitmapImage x 40, AnsiString x 1, Unknown x 18

117 - 132 bytes: TPopupMenu x 1, TImageList x 12, TDragImageList x 9, AnsiString x 2

133 - 148 bytes: AnsiString x 2

149 - 164 bytes: TAction x 66, AnsiString x 1, Unknown x 1

165 - 180 bytes: TMenuItem x 3, TRVRTFReaderProperties x 7, AnsiString x 1, Unknown x 3

197 - 228 bytes: TDateTimeField x 8, TActionManager x 1, TStringField x 95, Unknown x 2

229 - 260 bytes: TSmallintField x 7, TIntegerField x 27, TMemoField x 17, TZGenericSQLWordState x 1, TZWhitespaceState x 1, Unknown x 1

261 - 292 bytes: TRichViewRVData x 7, AnsiString x 1, Unknown x 1

293 - 324 bytes: Unknown x 1

325 - 356 bytes: Unknown x 1

357 - 404 bytes: Unknown x 2

405 - 452 bytes: TToolButton x 4, TColoredLabel x 13, TLabel x 9

501 - 548 bytes: TSplitter x 8

549 - 612 bytes: TZQuery x 9, TGroupBox x 22

613 - 676 bytes: TTrayIcon x 1, TBitBtn x 10, TPanel x 24, TTabSheet x 10

677 - 756 bytes: TListBox x 4, TComboBox x 13, TPageControl x 1

837 - 932 bytes: TToolBar x 1, TColoredCtgButtons x 8

933 - 1028 bytes: TWebBrowser x 1, TListView x 1

1029 - 1140 bytes: TZGenericSQLTokenizer x 1, TRichView x 7, Unknown x 262

1381 - 1524 bytes: TJvDBSMGrid x 6

1685 - 1860 bytes: Unknown x 1

2261 - 2484 bytes: TfrmMain x 1



The sizes of leaked medium and large blocks are (excluding expected leaks registered by pointer): 16564, 4532, 4532, 4532, 4532, 4532, 4532, 4532, 4532, 8372



Note: Memory leak detail is logged to a text file in the same folder as this application. To disable this memory leak check, undefine "EnableMemoryLeakReporting".
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

If this option is included, all tags are treated as pointers to strings allocated by StrNew.
If you pass other values as tags (such as integer numbers or pointers to other objects), an error will occur when freeing memory.
Check all places in you applications where you assign item's tags.
Post Reply