DllHost.exe memory leak when getting PrintTicket

178 views Asked by At

I have a x86 application working on windows10 (64 bit environment). One pf the app's features is to generate a lot of reports, so there is a lot of printing involved. However, I noticed that every time I try to use call DefaultPrintTicket on the print queue the dllhost process (COM Surrogate) grows in memory.

I managed to isolate the code responsible and moved it to a test WPF app. When a button is clicked this code is being fired:

var localPrintServer = new LocalPrintServer();
var oneNotePrintQueue = localPrintServer.GetPrintQueues().FirstOrDefault(p => p.Description.Contains(OneNote));
var printTicket = oneNotePrintQueue?.DefaultPrintTicket;

The printing queue is irrelevant as I tried them all and the problem remains. I am aware that this might be a duplicate to: PrintTicket DllHost.exe Memory Climbs

However, the solution provided there does not work as PrintTicked is not an IDisposable object. I also tried some tweaks in the registry (i.e. finding AppId AA0B85DA-FDDF-4272-8D1D-FF9B966D75B0 and removing "AccessPermission", "LaunchPermission" and "RunAs") with no result.

I cannot rebuild the app as AnyCpu and I would like to avoid creating a separate 64bit process just for printing as it would be difficult to send a report generated in one app to another.

Any suggestions are greatly appreciated.

1

There are 1 answers

0
Yamamotooko On BEST ANSWER

It seems that the topic is difficult. Just want to share the solution I went with in case anyone else has the same problem.

In the end I created a separate x64 app which handles the printing. Initially I wanted to go with a WCF service. However, I ran into problems with serializing of FixedDocuments and PrintQueue. Hence the separate app.

The solution if far from perfect and in my opinion is not nice at all. However, it solved the memory leak issue.