Acrobat PDF viewer control takes time to dispose

984 Views Asked by At

This issue affects both my VB.NET and C# Winform applications. When closing Form containing Adobe PDF Viewer conreol, the Form takex some 10 seconds to close. I tracked the issue down to Dispose method. Normally, in C# all it takes it so steal focus from Adobe PDF Control by adding lines to FormClosing event handler but in VB.NET, even if I steal focus, it still takes way too long for the Form to close. I tried to explicitly dispose the control and Implicitly - by disposing the containing Form. I tried empty string in LoadFile() method. I tried new reference to new interop library. Nothing works. Also, if you would suggest a different API/library to replace AxAcroPDFlib I'd love to read what you use.

1

There are 1 best solutions below

0
On

I now have a solution. Early testing is promising. In short, add Controls.Remove(yourPdfViewerControl) to FormClosing event handler. Of course this will offer instant alleviation of the problem but may cause memory leak. After you have removed the control from Container you could assugn null to its memory address and hope that memory manager will do its job.

So in order to prevent the leak, I created a class holding one memory space for PdfViewer control. If a Form needs a viewer, it requests it from an object that is accessible from any form to prevent memory leaks. To avoid Dispose method invocation when Form closes, make sure you remove this Control from Controls container. I can provide sample code if needed.