Quantcast
Viewing all articles
Browse latest Browse all 18858

wpf richtextbox memory leak,how to resolve

I use WPF RichTextBox control to show dynamic log info like this:

public void AppendLoginfo(LogInfo loginfo)
{
if (txtMsg.Document.Blocks.Count > 100)
{
txtMsg.Document.Blocks.Remove(txtMsg.Document.Blocks.FirstBlock);
}
Run body = new Run(loginfo.Body);
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(body);
txtMsg.Document.Blocks.Add(paragraph);
}

This application's memory is growing all the time when I using,and then OutOfMemoryException!

How can I fix it?

THX!


Viewing all articles
Browse latest Browse all 18858

Trending Articles