pcorless / icepdf

PDF Rendering and Viewing API in Java
Apache License 2.0
81 stars 21 forks source link

file still open when call closeDocument #323

Closed annpeter closed 9 months ago

annpeter commented 11 months ago

1、I use icepdf to open one pdf file 2、close the pdf in icepdf(call the closeDocument method), not close the application 3、I go to File Manager for Operating System, then change the file name i had open before. 4、I received an error indicating that the file is still open

image

pcorless commented 11 months ago

I just pushed a branch that has few small changes. However, after a bit of debugger time I can't see any dangling file descriptors or input streams laying around after the document is closed. That said I am on linux and the file system config is a bit different then on windows.

Did you happen to save file changes or export changes? Or was simply open and close a document?

annpeter commented 11 months ago

I have did some research and it appears that the MappedByteBuffer maps the memory of the file, but Java does not provide an interface to control the closure of this MappedByteBuffer mapping.

https://stackoverflow.com/questions/25238110/how-to-properly-close-mappedbytebuffer

The process of research is as follows: I first debugged step by step to determine which code segment the file would be occupied after entering, and when I called this MappedByteBuffer, I added my own code and immediately closed documentFileChannel, but still couldn't release the file

image

pcorless commented 11 months ago

Thank you for pointing me at that issue. And it would seem to explain why I'm not seeing it on Linux. I've updated the above branch with a more memory intensive change that might get around the lock issue you are seeing. If you have the means please let me know if it corrects the problem on Windows.

annpeter commented 11 months ago

yes, it works.

pcorless commented 9 months ago

Will be in the 7.1.4 release.