re-editor icon indicating copy to clipboard operation
re-editor copied to clipboard

Memory leak when you try to insert a line to a large text

Open doonfrs opened this issue 1 year ago • 3 comments

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. set a large text to the editor
  2. for loop from 1 to 100
  3. textController.text += 'anytext';
  4. the memory will increase on each loop and it will not released.

Expected behavior insert a new line without the need to read the text ( get/set ) with text+= because the text property is CPU and memory-heavy. I expect a method like insertLine, insertText

Device:

  • OS: windows
  • Version 0.6.0

doonfrs avatar Dec 01 '24 22:12 doonfrs

I fixed it by using the following approach:


    _logController.moveCursorToPageEnd();
    _logController.replaceSelection('\n$url : ');

the memory is not going up anymore, but I still believe something like insertText will be helpful.

doonfrs avatar Dec 01 '24 22:12 doonfrs

@doonfrs I think it may be a cache issue. Since Flutter's paragraph is very expensive, the editor will cache the result and will not release it until the editor is destroyed.

MegatronKing avatar Dec 05 '24 06:12 MegatronKing

@MegatronKing Thank you for your reply, Yes, I think we have two issues: 1 - Memory leak, the editor never releases the memory used in the text get method, if I have 50 MB of text, and I call text 10 times, I will end up with 50X10 of data in the memory, my app reaches 32 GB. 2 - I found that replaceSelection is a good alternative.

doonfrs avatar Dec 05 '24 07:12 doonfrs