Jump to content
Sign in to follow this  
JRadke

SynEdit with memory leak?

Recommended Posts

I use SynEdit as replacement for TMemo to list permanent incoming data. To prevent a memory overflow I limit the number of rows like this:
 
Synedit1.Lines.Add('My new data...');
if SynEdit1.Lines.Count > 150 then SynEdit1.Lines.Delete(0);

This will limit the number of rows to 150, but the allocated memory is not released by the Delete command (checked with memoryManager), so at some point I get a memory overflow.

This behaviour happens since upgrading from Delphi 10.4 to Delphi 11 and SynEdit respectively (2022.03-11).

 

Share this post


Link to post

Assuming you are using the Turbopack Synedit:

 

Changes to the text buffer are undoable.   So just calling Delete does not clear all related memory.    You need to do one of:

  • call ClearUndo every now and then to release the undo/redo memory.
  • Set MaxUndo to some number to limit the undoable actions.  The default is 0 (unlimited undo/redo).
  • call LockUndo/Unlock undo to prevent actions being added to the undo/redo stack (the most efficient).

If you still get a memory overflow then this is a bug that you should report.

 

Edited by pyscripter
  • Like 1

Share this post


Link to post

My testing with MaxUndo = 1 (to most closely match a TMemo) doesn't show any leaks.  I've also tested the other scenarios with no leak issues that I could detect.  It's very true that the default settings can chew through a lot of memory for the undo stuff, so in the case of a log like this you must limit or manage the undo.  On a related note:  Am I correct that LockUndo/UnlockUndo must always be followed by a ClearUndo in order to keep everything in sync?  I wasn't' sure if that happened automatically or perhaps is just not an issue.

 

-Mark

 

@pyscripter

I'm very impressed by how few issues there have been for such a major rewrite!  Well done!

 

Share this post


Link to post

You can use LockUndo to disable Undo altogether.

LockUndo/UnlockUndo is also useful when you read a file or initially setup a text buffer.  If the Undo buffer is not empty then you would want to call ClearUndo before or after.

Edited by pyscripter

Share this post


Link to post

Thank you for the answers.
The consideration of the undo/redo memory seems plausible to me, I will try that out.

 

-Jürgen

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×