Microsoft KB Archive/943823

= A WPF application that uses a VisualBrush object in a RichTextBox control encounters a memory leak when you try to clean up the RichTextBox control =

Article ID: 943823

Article Last Modified on 11/28/2007

-

APPLIES TO


 * Microsoft .NET Framework 3.0

-



SYMPTOMS
In a Windows Presentation Foundation (WPF) application, you use a VisualBrush object in a RichTextBox control. When you try to clean up the RichTextBox control, a memory leak occurs. Additionally, the application crashes.



CAUSE
This problem occurs because not all channels are completely closed.



WORKAROUND
To work around this problem, call the RenderTargetBitmap object three times to clear all the channels. For example, run code that resembles the following in the application: Dim oCanvas As New Canvas renderBmp = New RenderTargetBitmap(1, 1, 96, 96, PixelFormats.Pbgra32) renderBmp.Render(oCanvas) renderBmp.Clear renderBmp = New RenderTargetBitmap(1, 1, 96, 96, PixelFormats.Pbgra32) renderBmp.Render(oCanvas) renderBmp.Clear renderBmp = New RenderTargetBitmap(1, 1, 96, 96, PixelFormats.Pbgra32) renderBmp.Render(oCanvas) renderBmp.Clear



MORE INFORMATION
The RenderTargetBitmap object opens a new synchronous channel to the Media Integration Layer (MIL). Therefore, the RenderTargetBitmap object does not communicate through the main asynchronous channel. After the synchronous channel is opened, the RenderTargetBitmap object performs the following operations:
 * 1) Marshals all objects onto the synchronous channel.
 * 2) Performs the Render operation.
 * 3) Obtains a return image.
 * 4) Removes all objects from the channel.
 * 5) Closes the channel.

However, the channel is not completely closed. Therefore, a memory leak occurs. The memory leak causes the application to crash.

Keywords: kbexpertiseadvanced kbtshoot kbprb KB943823

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.