When a computer starts running extremely slow and a simple restart fixes it, what is really happening?

444 views

When a computer starts running extremely slow and a simple restart fixes it, what is really happening?

In: 216

12 Answers

Anonymous 0 Comments

Some of the comments provide part of the answer, but it helps to know another potential issue. First, imagine that you know that if you have to go to work, you go North 500 meters, then turn 90 degrees to the right, go 100 meters, then turn to the left 90 degrees and go another 1000 meters. To go home, you go the opposite direction. To go to the grocery store, you go North 100 meters, then turn 45 degrees to the left and go 650 meters, then turn 120 degrees to the left and go 50 meters. Again, to go home, you do the opposite.

Now, imagine that one day, you get interrupted on a trip. If you were close enough to a turn, you might be able to figure out where you were, but if you were in the middle of a travel, you might not know how much further you were supposed to go. All you know how to do is give up or restart your directions. Neither of those will allow you to get to your destination, so you are in an “unknown state”, literally not knowing where you are or where to go next.

Programs are very much like this, being explicitly told to go two memory addresses, get the contents, then subtract one from the other. If something happens and the program goes to the wrong address, it might try subtracting “5” from “Red Enemy” with unpredictably results. Most modern programming is better at handling this (predictably called “error handling”), where it can identify that it had a problem, then do something else (like just return “5” for the answer, which is wrong, but closer than trying to subtract a number from a sentence!). Additionally, it can report an error in a log or a display on the screen. Error handling can happen at multiple levels, so if that specific instruction does not have error handling, the program can go the next level up (ie., whatever the program was doing where it needed to subtract the numbers) and allow that to handle the error.

In some cases, there is no error handling or the error handling does not know what to do, the program might crash. Or, it might continue but act strangely (such as video, audio, or movement glitches, repeating a level, etc), or maybe even continue to work but when you quit the program, it never closes fully. Then, you have the equivalent of the car driving aimlessly around, trying to get to work or home but fated to never arrive.

One of those is not a big problem, but when you have 10,000 or 10 million aimless drivers, it makes it incredibly difficult for legitimate drivers to get where they are going as well.

Restarting helps since it sets everything back to its default state. When the computer boots (or reboots), it does the equivalent of setting every car in its own driveway, and ensures every driver has the correct instructions on where it is going. With everything in a known state, all cars are either sitting at home (the given program is not running) or correctly going to their destinations (the given program is running correctly).

I feel like some of the examples in other comments are good, but most modern programming should clean up after itself without issue. If I decide to play Super Auto Pets for a few minutes (or a few hours) then exit it, it cleans up everything (ie., gets all of its cars back home) without issue. The computer is left in basically the same state after the game as it was before. As a result, many modern computers can run for a month or more without issue, only rebooting for hardware changes or OS updates. There are exceptions, where either poor programming (or excessively hurried software development to meet an arbitrary deadline) or some local issue with the hardware/OS/installation of the program causes a memory leak or leaves part of the program in an unknown state even after it quits. However, anyone who has been using a computer for a decade or more should remember how much worse it used to be. Between the operating system and software, weekly reboots were not uncommon, and I distinctly remember needing to reboot my computer before/after playing some video games (since the “leftover” bits of running program would cause issues if the program was run again).

You are viewing 1 out of 12 answers, click here to view all answers.