Hello Victor,
A possible workaround is to handle the DocumentUnloaded event of the element and clear the objects causing the memory leak:
private void PdfViewerElement_DocumentUnloaded(object sender, EventArgs e)
{
RadPdfViewerContainer container = this.PdfViewer.PdfViewerElement.Parent as RadPdfViewerContainer;
if (container != null)
{
foreach (var node in container.BookmarksTree.TreeViewElement.GetNodes())
{
node.Tag = null;
}
container.BookmarksTree.Nodes.Clear();
}
typeof(RadPdfViewerElement).GetField("previousPage", BindingFlags.NonPublic | BindingFlags.Instance).
SetValue(this.PdfViewer.PdfViewerElement, null);
}
Additionally, it may also be necessary to force the GC:
// If running on .NET 4.5.1 and later
// https://docs.microsoft.com/en-us/dotnet/api/system.runtime.gcsettings.largeobjectheapcompactionmode?view=net-5.0#System_Runtime_GCSettings_LargeObjectHeapCompactionMode
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
//
GC.Collect();
GC.WaitForPendingFinalizers();
GC.WaitForFullGCApproach();
GC.WaitForFullGCComplete();
GC.Collect();
Regards,
Hristo
Progress Telerik