Memory leak still persists

General TRichView support forum. Please post your questions here
Post Reply
escovadordebits
Posts: 2
Joined: Fri Jul 20, 2007 8:54 pm
Location: Brasil

Memory leak still persists

Post by escovadordebits »

Sorry for my bad english, because I'm a brazilian nerd, and my first language is brazilian portuguese. :D
I've download the ActionTest.exe demo to verify if it has the same memory leak bug that my application has.
I just had copied the text wich appears in the editor and pasted it.
I repeat this process several times (copy all text and paste it to duplicate it).
After all, I just selected the entire text and I've pressed the delete key, clearing all the editor.
Visually, the entire text had disappeared, but the biggest part of the used memory still remains (memory leak?).
When I select "File -> New" menu item, that unused memory is freed at last.
Which code sequence I must execute to free all the used memory by the RichView component (Delphi5).
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Deleted text is stored in undo buffer until you call File | New or File | Open.
See also: UndoLimit property.

ClearUndo method clears undo and redo buffers.
Clear method calls ClearUndo.
escovadordebits
Posts: 2
Joined: Fri Jul 20, 2007 8:54 pm
Location: Brasil

Unhappy, memory leak still remains

Post by escovadordebits »

Thank you for your quick response, but it didn't work as expected.
I called explicitly the Clear and ClearUndo, but the memory leak still remains.
I made a example application, in Delphi5, with only one form.
In this form, I put a TRichViewEdit, a TRVStyle and tow buttons.
The first button is the "fill" button, and it just fills the RichViewEdit with a lot of text, just selecting all text, copying it to clipboard, and pasting it tow times to duplicate it like I made manually.
Its code is the following:

Code: Select all

procedure TExampleMainForm.ButtonFillClick(Sender: TObject);
const
  inDuplicationCount = 11;
var
  inIndex: Integer;
  stText: String;
  pcCurrent: PChar;
begin
  ButtonFill .Enabled := False;
  ButtonClear.Enabled := False;
  try
    // Create a 10Kb text (randomic uppercase letters).
    SetLength(stText, 10240);
    pcCurrent := PChar(stText);
    for inIndex := 1 to Length(stText) do
    begin
      pcCurrent^ := Chr(Random(26) + 65); // A to Z.
      Inc(pcCurrent);
    end; // for
    // Clear the current text.
    RichViewEditMain.Clear;
    // Put the new text.
    RichViewEditMain.InsertTextW(stText + #13);
    // Free the internal copy of the original text.
    stText := '';
    // Text dupplication loop.
    for inIndex := 1 to inDuplicationCount do
    begin
      // Show the current progress in the button caption.
      ButtonFill.Caption := IntToStr(inIndex) + '/' +
                            IntToStr(inDuplicationCount) + ' (' +
                            IntToStr((inIndex * 100) div inDuplicationCount) + '%)';
      // Select the entire current text.
      RichViewEditMain.SelectAll;
      // Copy it to clipboard as RTF text.
      RichViewEditMain.CopyRTF;
      // Past it two times to duplicate it.
      RichViewEditMain.Paste;
      RichViewEditMain.Paste;
    end; // for
  finally
    ButtonFill .Caption := '&Fill';
    ButtonFill .Enabled := True;
    ButtonClear.Enabled := True;
  end;// try-finally
end;
The second button is the "clear" button, and this code is the following:

Code: Select all

procedure TExampleMainForm.ButtonClearClick(Sender: TObject);
begin
  RichViewEditMain.Clear;
  RichViewEditMain.ClearUndo;
  RichViewEditMain.RVData.Refresh;
end;
When this application is running, I click in the "Fill" button, and the memory usage of the application comes to 73Mb (average).

When I click the "clear" button, the application memory usage comes to 17Mb, not the initial memory usage value.

Unhappy, changing the value of the UndoLimit had no any effect.

I'm using the TRichViewEdit version 1.9.15.1 for Delphi 5.

Please, help me with this problem.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

What tool do you use to see how much memory the application use? It may be inaccurate, it may show memory that was released by the application but was not returned to the system yet.
Try to minimize the project and restore it, after that the tool may show the proper amount of memory the application use.
I tested this code in MemProof, it does not show any memory leak except for allocating memory in CopyRTF for the Clipboard, but it is expected because this memory will be freed by Windows, not by the application.
Post Reply