Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemoryLeak in net 462 #386

Open
SuperStudio opened this issue Feb 5, 2023 · 3 comments
Open

MemoryLeak in net 462 #386

SuperStudio opened this issue Feb 5, 2023 · 3 comments

Comments

@SuperStudio
Copy link

SuperStudio commented Feb 5, 2023

There seems to be a memory leak

This is my step:

  1. Pull the latest master branch, compile version 462, and run sample code
  2. Paste and then empty about 1M of text
  3. After try 10 times, the memory reaches 500MB

However, the text has been emptied at last, and the memory is still not recycled

Before
image

After 10 minute

image

@jogibear9988
Copy link
Member

I don't know, but didn't avalonedit have a undo stack? maybe this keeps all in memory? and if there is one (wich i don't know atm), isn't there an api to clear?

@SuperStudio
Copy link
Author

I don't know, but didn't avalonedit have a undo stack? maybe this keeps all in memory? and if there is one (wich i don't know atm), isn't there an api to clear?

However, even use TextDocument.UndoStack.ClearAll() not work.

The only way is that to set TextEditor = null and then new TextEditor() to let GC work itself

@SuperStudio
Copy link
Author

I don't know, but didn't avalonedit have a undo stack? maybe this keeps all in memory? and if there is one (wich i don't know atm), isn't there an api to clear?

However, even use TextDocument.UndoStack.ClearAll() not work.

The only way is that to set TextEditor = null and then new TextEditor() to let GC work itself

set TextEditor = null and then new TextEditor() still cause MemoryLeak.

Sample Code:

private async void TryWithSetNull(object sender, RoutedEventArgs e)
{
    await Task.Run(async () => {
    for (int i = 0; i < 100; i++) {
	    App.Current.Dispatcher.Invoke(() => {
		    editor.Text = SampleText;
	    });
	    await Task.Delay(50);
	    App.Current.Dispatcher.Invoke(() => {
		    editor.Clear();
                    editor.ClearUndo(); // clear undo stack
		    editorGrid.Children.Clear();
		    editor = null;
		    editor = CreateTextEditor();
	    });
    
    }
    });
    button.IsEnabled = true;
}


public TextEditor CreateTextEditor()
{
    editor = new TextEditor();
    editor.BorderBrush = Brushes.Blue;
    editor.BorderThickness = new Thickness(1);
    editorGrid.Children.Add(editor);
    return editor;
}

// in TextEditor.cs
public void ClearUndo()
{
    TextDocument document = this.Document;
    document.UndoStack.ClearAll();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants