More specifically, why are so many left and not deleted?
There are indeed many temporary files. As I write this, my primary machine has 322 files in its temporary folder totaling 58 megabytes. My example PC, which isn’t used nearly as heavily, has 134 files totaling 78 megabytes.
Just as there are many files, there are also many reasons they get left behind.
Become a Patron of Ask Leo! and go ad-free!
Temporary files in Windows
Temporary files accumulate due to crashes, improper shutdowns, running programs, updates, caching, logging, and sometimes just poor programming. While they’re supposed to be deleted automatically, some scenarios leave them behind. Tools like Windows Disk Cleanup or Storage Sense can help remove them.
Why temporary files at all?
A temporary file is, as the name implies, a file on your hard disk that is created by software and is intended to be temporary. When the program finishes using the temporary file, it deletes it. You’re never intended to see it.
Programs use temporary files for a variety of reasons, including:
- Needing to operate on more data than is practical to keep in RAM.
- Data that preserves the state of software over some time.
- Data that might be used to implement features like “undo” and “redo” in applications.
- Logs, transaction logs and journals1, internally managed caches, and more.
- …whatever else the program designer might want them for.
The reasons are as varied as the programs are.
As I said, the intent is for temporary files to be cleaned up at some point.
The reason we’re here, of course, is that good intentions aside, that doesn’t always happen.
Viewing temporary files
The easiest way to view your temporary files is to enter “%TMP%” in Windows File Explorer:
This opens the temporary folder for your login account. (Each account has its own, as does the system itself at C:\Windows\Temp.)
You can see that my temp folder is located in C:\Users\lnote\AppData\Local\Temp. It has 382(!) items in it, consisting of many oddly named folders and files.
Many have been left behind for some reason.
Let’s look at some of those reasons.
Crashes
This is probably what comes to mind first for most folks. If a program that uses temporary files crashes, it doesn’t have a chance to delete the temporary files it was using. Some programs are written to clean up previously existing temporary files the next time it runs, but I’d say most do not.
And of course, Windows is a program that uses temporary files. If Windows crashes, it won’t have an opportunity to clean up.
Shutdown
An improper shutdown can leave temporary files behind. If you’ve ever had to long-press the power button to shut down Windows, that behaves much like a crash. Whatever temporary files are in use at the time remain. A “normal” shutdown — using either Shutdown or Restart — gives the operating system a chance to clean up on the way out.
Running programs
Of course, if a program is currently running and it uses temporary files, you’ll find those. There’s a lot of software running on your machine from the moment you fire it up to the moment you shut it down. Much of that software, such as services and background applications, you never see.
Updates and rollback
Windows and other software updates may leave behind temp files to assist with installation or rollback. Particularly for rollback, those temp files will be left behind. The side effect of deleting those temp files might be the inability to roll back an update.
Caches
I have a couple of programs on my machine that, the first time you run them, perform one-time configuration, or even lengthy calculations the first time you run them. Those calculations are preserved for subsequent runs. Sometimes the results of configurations are saved as temporary files. Deleting those temporary files forces the program to repeat its initialization the next time it’s run.
Logging
Some programs make a log of particular actions or other activities as it does their job. By not deleting those logs they remain available for analysis during troubleshooting.
Bad programming
This has to be mentioned, as it’s probably the second reason most people think of when looking at long lists of temp files. There are two ways poor programming increases the number of temp files.
- Using the system’s temporary file location when an app-specific location might be more appropriate. In the caching example above, for instance, the application should be keeping its cached information in its own folders to more properly manage those files. Putting them in the system temp folder means they may get unexpectedly deleted or, in severe cases, damaged by other programs.
- Just bad code. Sometimes software is written to use and create temporary files without thinking through all the scenarios in which they should be cleaned up.
Another way to view and clean up temp files
Search the Settings app for “storage”. On the resulting page, click on the line for Temporary Files.
This will present the categories of temporary files currently on your machine along with descriptions and the option to delete some or all of them.
Do this
For the most part, temporary files are not something you need to worry about often. If you do, tools like Windows Disk Cleanup or Storage Sense give you a quick and easy way to clean ’em up.
Subscribe to Confident Computing! Less frustration and more confidence, solutions, answers, and tips in your inbox every week.
Podcast audio
Footnotes & References
1: These aren’t typically human-readable logs, but logs used by the application to maintain, repair, and analyze other data structures.
From my experience, I’d say bad programming is the main cause of temporary files on my machine. Even when I haven’t exited a program via Task Manager or had any of the other scenarios mentioned in the article, I get dozens of temp files in the %temp% folder and other locations. I run Disk Cleanup a couple of times a week, especially on my laptop with a small 500 GB drive.
I delete temp files when I run a weekly scan. Both free utilities that I use offer that option before starting the scan.
Are they really clearing them all, or is that an illusion and I should be using a method detailed in this article?
You don’t mention which programs you are using to scan, but you can check your free space before and after clearing the temp files. I’d run Windows cleanup anyway because it’s likely that it clears temporary files in more places.
Depends on the free utility you run. Tools like CCleaner, Glary, JV16 all work.
Who needs a utility? We routinely delete temporary files from c:\Temp nightly using the great file manager Directory Opus (but you could use Windows Explorer or any other file manager that you fancy). For decades, I’ve set up our computers to place all temporary files in c:\Temp. At the end of the day, we just open that directory (now I’m really giving away my age) in our file manager and select all the temp files and delete. The literal handful that cannot be deleted simply are not deleted. Then I just empty the recycle bin. Takes all of 10-20 seconds which I imagine anybody can spare. Then we shut down the computers for the night (we’ve got absolutely no reason on earth to leave them on overnight.)
I sometimes do that, but utilities like Disk Clean Up and CCleaner clean more temporary files, includig the Recycle Bin and tempory browser files and others. I may not be of concern to you but it’s useful for many.