Right now, Blender just stores its temp files in temp directory. In some cases, it even uses PID to avoid several instances of it using the same files (at least, for point caches of unsaved .blends, and added that behavior to fix T39521, see rB6cd717e0a3c6).
The issue is that Blender never removes those files, and some OSs (Windows…) never clean up their temp dir, which can leads to a quick waste of space. So here is the proposition (also from discussion with Campbell):
- At startup, Blender creates a (PID-tagged) folder in temp dir, where it stores all files that are really temp ones.
- When closing, Blender removes that folder and all its content.
For the very few cases where we need a 'cross-session' persistent 'temp' files (only render result afaik?), we could create temp file directly in main tmp dir (not in Blender session’s PID-tagged one).
The issue here is how to avoid several instances to use the same 'persistent' file? We could use locks, but I can’t find a nice way to handle them (main issue being to handle crashes, which are one key reason to have those persistent render results). Or maybe we just decide this is a corner case we do not want to support (i.e. in situations like T39521, we simply accept both processes write the same temp render result file - intermediate samples being saved in PID temp folder anyway)?