What causes a program to lag?

2.18K views

Imagine you finished browsing on chrome and want to end your session… You click on that red X to close everything… And then your computer just hangs there. What causes this lag? Theoretically shouldn’t the computer be erasing stuff from memory, not lagging?

In: Technology

4 Answers

Anonymous 0 Comments

Your computer lags because there is insufficient resources available to perform tasks in real time.

Resources include CPU time, the amount and speed or you RAM, and how long it takes your hard drive to catch up.

Hard drives are by far the slowest component of your computer, so the less time you spend reading + writing to it the faster your computer will be.

If you are short on RAM your computer will begin dumping RAM contents to your Hard drive to free up space. A process called swapping.

It’s also possible your CPU is busy doing something else like loading another program.

Sometimes though it’s bad code. The program is written in an inefficient manner which causes it to use an unnecessary amount of resources for a given task.

Anonymous 0 Comments

Fun fact, your computer CANNOT MULTITASK. instead it switches apps VERY FAST and work on them. so fast is seems like its happening all at once.

All the meanwhile, stuff is being shoved into RAM, random access memory. When that RAM is stuffed, GG WP, computer freeze.

ELI5, try to do 2X2X2X…. at some point you just forget or freeze up.

THERE IS ALSO the other case, where faulty code pops up, causing a endless loop, and your pc have no idea what to do, it keeps excecuting this line of code and is just stuck there.

This is why its so important to QC programs.

Anonymous 0 Comments

‘Erasing memory’ includes:

– writing to special tables in memory that previously occupied RAM is free

– closing all files, finishing writing to them, probably deleting some of them (and browser opens & creates tons if files)

– closing all sockets

– waiting for all subprocesses to close. if you have 100 processes and each writes 100 bytes to a drive before closing, that may take a noticeable amount of time as they can’t write all at once.

that being said, I don’t know why Windows struggles THAT much with closing apps. on other systems its more fluid, firefox on Linux closes nearly instantly.

Anonymous 0 Comments

The os could close the program fast by simply not giving it more cpu time and releasing all the resources associated (memory, files, windows, sockets, whatever). It doesn’t do that because programs like to do their own cleanup as well, so when you press the X it just signals to the program to please close yourself. If for example it has a ton of data it wants to write down to disk or just too many open files, or reports back to some network address about something, it’ll take some time.