MuPDFCore icon indicating copy to clipboard operation
MuPDFCore copied to clipboard

Bug or feature: document.Dispose() does not include disposing document.Pages[..]

Open tih2010 opened this issue 5 months ago • 2 comments

Hi!

Recently I got an hard crash with this error

ScanProcessingService.exe CoreCLR Version: 8.0.1925.36514 .NET Version: 8.0.19 Description: The process was terminated due to an unhandled exception. Exception Info: MuPDFCore.LifetimeManagementException`2[MuPDFCore.MuPDFPage,MuPDFCore.MuPDFContext]: The current MuPDFPage instance (2468838EAB0) was disposed after its owner MuPDFContext instance (24641321020) had already been disposed. This may happen if the MuPDFPage instance has not been properly disposed. Please ensure that all instances of classes implementing IDisposable are properly disposed in the correct order (e.g., by wrapping them in using statements). at MuPDFCore.MuPDFPage.Dispose(Boolean disposing) at MuPDFCore.MuPDFPage.Finalize()

(I only happens on my customers limited machine.. I can't reproduce it).

At first I couldn't explain what was going on, since this error occurs very rarely...

I am using muPdf like this:

  • create context
  • create document
  • do stuff with pages in document.Pages[...]
  • dispose document
  • dispose context

Looking at the Dispose()-method of the document-code I saw that the

public MuPDFPageCollection Pages { get; private set; }

is not disposed in the process of disposing the document-object.

I am not sure if this is on purpose. I would expect the MuPDFPageCollection to be disposed as well, but there may be reasons not to do so.

I'll try to add one more step...

  • create context
  • create document
  • do stuff with pages in document.Pages[...]
  • dispose document.Pages
  • dispose document
  • dispose context

and see what happens.

But of course I am interessted in your opinion on this :-)

Best, Wolfram

tih2010 avatar Sep 10 '25 15:09 tih2010