Hello,
We use Telerik UI for WinForms (2022.3.1109) on .NET Framework 4.8. Our application creates and disposes many RadPdfViewer instances during a session, and it eventually fails with GDI+ errors.
What we see
Each RadPdfViewer that is created and disposed leaves 12 GDI objects and 4 USER objects behind (measured with GetGuiResources). The viewer does not have to be shown or load a document. When the process reaches the 10,000 GDI object limit, creating the next viewer fails.
Repro
Output:
Workaround we are testing
When a viewer is created, we use reflection to collect the handles of its pan cursors, and we call DestroyIcon on them when the viewer is disposed. With that in place the same repro runs all 3,000 viewers and the counts stay flat at 12 GDI and 9 USER objects.
Questions
We use Telerik UI for WinForms (2022.3.1109) on .NET Framework 4.8. Our application creates and disposes many RadPdfViewer instances during a session, and it eventually fails with GDI+ errors.
What we see
Each RadPdfViewer that is created and disposed leaves 12 GDI objects and 4 USER objects behind (measured with GetGuiResources). The viewer does not have to be shown or load a document. When the process reaches the 10,000 GDI object limit, creating the next viewer fails.
Repro
[DllImport("user32.dll")] static extern int GetGuiResources(IntPtr process, int flags);
[DllImport("kernel32.dll")] static extern IntPtr GetCurrentProcess();
[STAThread]
static void Main()
{
IntPtr process = GetCurrentProcess();
int i = 0;
try
{
for (i = 1; i <= 3000; i++)
{
RadPdfViewer viewer = new RadPdfViewer();
viewer.Dispose();
if (i % 100 == 0)
{
GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect();
Console.WriteLine("{0} viewers: GDI {1}, USER {2}", i, GetGuiResources(process, 0), GetGuiResources(process, 1));
}
}
}
catch (Exception ex)
{
Console.WriteLine("viewer {0}: GDI {1}, USER {2}", i, GetGuiResources(process, 0), GetGuiResources(process, 1));
Console.WriteLine(ex);
}
}Output:
100 viewers: GDI 1212, USER 409 200 viewers: GDI 2412, USER 809 300 viewers: GDI 3612, USER 1209 400 viewers: GDI 4812, USER 1609 500 viewers: GDI 6012, USER 2009 600 viewers: GDI 7212, USER 2409 700 viewers: GDI 8412, USER 2809 800 viewers: GDI 9612, USER 3209 viewer 833: GDI 9996, USER 3337 System.Runtime.InteropServices.ExternalException (0x80004005): A generic error occurred in GDI+. at System.Drawing.Bitmap.GetHicon() at Telerik.WinControls.PdfViewer.MouseHandlers.PanHandler..ctor(MouseHandlersController controller, IFixedDocumentPresenter presenter) at Telerik.WinControls.PdfViewer.MouseHandlers.MouseHandlersController.BuildHandlers(IFixedDocumentPresenter presenter) at Telerik.WinControls.UI.RadPdfViewerElement..ctor() at Telerik.WinControls.UI.RadPdfViewer.CreateViewerElement() at Telerik.WinControls.UI.RadPdfViewer.CreateChildItems(RadElement parent) at Telerik.WinControls.RadControl.Construct() at Telerik.WinControls.RadControl..ctor() at Telerik.WinControls.UI.RadPdfViewer..ctor()
Workaround we are testing
When a viewer is created, we use reflection to collect the handles of its pan cursors, and we call DestroyIcon on them when the viewer is disposed. With that in place the same repro runs all 3,000 viewers and the counts stay flat at 12 GDI and 9 USER objects.
Questions
- Is this a known issue in 2022.3.1109?
- Is it fixed in a later release?
- Is there a better workaround, and is the reflection route safe?