I'm currently working on an ASP.NET API in .NET 7. Users can upload PDF files to it, all contained images are extracted from it and those are then analyzed regarding color information. The details shouldn't be relevant as to what exactly is done.
The analyses themselves work perfectly fine, they always produce the expected output.
However, any temporary files created by ImageMagick in the process never get deleted despite all used resources being disposed correctly. Tons of "magick-*" files and tens of 720 MB files created every few minutes always remain.
I read about Magick obviously being unable to delete the files when an unrecoverable error occurs, but this is not the case; this happens even on 200-answered requests with the expected output.
There are also no problems regarding locks on the files. Once a new one is created, the previous one can be deleted without complaints by Windows, saying that the file is supposedly in use.
After a few 100+ MB PDFs, this really fills up the server, stopping at around 70 GB of undeleted temp files when the drive is finally full.
How can I circumvent this while still using Magick?
I expected any temp files to be deleted correctly. Instead, I need to do this manually.
EDIT: Here is a screenshot of what 15 minutes of work produced in the temp directory. Mind you, I merely cancelled the request, I did not stop the API in Visual Studio. If there is any clean-up, it would have have run.