I had a long discussion with Mendix on this topic. Jaap Pullemans response helped me the most:
-----My questions: what can cause this and how can i prevent this from happening in the future?
Mendix handles file transactions in a different way than database transactions. This is something we are aware of but this is not something that is trivial change.
What this means is that if you create a system$filedocument entity with binary data (=a file with contents) in a microflow the binary data will be written to disk as a physical file. If the microflow then runs into an exception the database entry will be rollbacked but the file on disk will remain.
Another case is where you delete an entity inheriting from system$filedocument from your domain model. On the next startup of the application the database table (of that entity) is removed from the database but the files remain on disk.
----I see that Mendix 6 contains a custom setting to cleanup orphaned files. Is this no longer available in Mendix 7?
That custom setting should not be used under any circumstances on a Production environment as it contains a critical flaw. The custom setting was removed at some point but it might still be present (albeit hidden) in (some) Mendix 7 (versions).
----Can you provide me an example script that fixes this, so i can create my own version of this?
We do not have such a script to share with you.
The presence of the file orphans in your case "only" has two detrimental effects:
1. It takes up unnecessary disk space.
2. Backups might be bigger than necessary.
The question is whether or not this is a major issue to you or not. If not, you could simply ignore the orphaned files. If so, we'll have to have an internal discussion to see what we can do to help you with this.
It might be just me, but this is something Mendix should fix. Now we do all kinds of workaround because Mendix dropped the ball here. How does Mendix solve this in their own cloud environment? I do know that it is a good practise to do a restore on itself once a year because that will also clean up a lot of diskspace because index tables are recreated and it should also clean orphaned files.
Mendix should just fic this or give instructions on how to solve this in an on premise installation.
Cant we just have a SE, that retrieves all files created before a certain date and delete them all.
We also create a lot of documents with our app. And we use the SE to clean them up.