Technology in terms you understand. Sign up for the Confident Computing newsletter for weekly solutions to make your life easier. Click here and get The Ask Leo! Guide to Staying Safe on the Internet — FREE Edition as my thank you for subscribing!

Why Are There So Many Temporary Files in Windows?

More specifically, why are so many left and not deleted?

Temp files can pile up. Why is that, and do you need to worry about them?
Windows File Explorer open on TMP folder with many files and folders.
So. Many. Temp. Files. (Image: askleo.com)
Question: Why are there so many temporary files left behind each time the computer is shut down and restarted?

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!

TL;DR:

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:

%TMP% in Windows File Explorer
%TMP% in Windows File Explorer. (Screenshot: askleo.com)

This opens the temporary folder for your login account. (Each account has its own, as does the system itself at C:\Windows\Temp.)

The contents of my Temp folder.
The contents of my Temp folder. Click for larger image. (Screenshot: askleo.com)

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.

Temporary Files in Settings.
Viewing temporary files in settings. Click for larger image. (Screenshot: askleo.com)

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

Play

Footnotes & References

1: These aren’t typically human-readable logs, but logs used by the application to maintain, repair, and analyze other data structures.

2 comments on “Why Are There So Many Temporary Files in Windows?”

  1. 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.

    Reply
  2. 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?

    Reply

Leave a reply:

Before commenting please:

  • Read the article.
  • Comment on the article.
  • No personal information.
  • No spam.

Comments violating those rules will be removed. Comments that don't add value will be removed, including off-topic or content-free comments, or comments that look even a little bit like spam. All comments containing links and certain keywords will be moderated before publication.

I want comments to be valuable for everyone, including those who come later and take the time to read.