MacOS – get serious execution lag on clicks, application switching and general usage

macbook promacosperformance

I have an MBP 8.1, early 2011, 13 inch, Mountain Lion. Whenever I leave it on for more than a couple hours, I get serious execution lag on every command. For example:

I click something (a link, button, command, even a tab in the browser) and the rainbow wheel of death shows up. After a couple seconds, my command gets executed.
I click on another app, and the app does the same before warming up for use – rainbow wheel of death, couple seconds of stall, revival, work.
Text edit and preview are sickeningly slow in opening the very smallest documents, so I've had to stop using them completely – the forced version control of 10.8. is not helping in the least.
Whenever I do anything I get this rainbow wheel of death lag prior to execution, and what's interesting is the fact that

a) The CPU usage NEVER spikes above 10% (I have it on scree at all times)

b) I actually have free RAM while doing this

I can find no processes hogging up the machine, and there are no fatal errors in the console showing up.

I use it for web development, so I have the following apps open at all times: a Java (I know, death to any machine) IDE running (PhpStorm), Chrome, Sparrow for mail, Twitter client and TotalTerminal.

That's all the apps I'm running.
Any ideas?

I'm willing to try anything except sending it to an Apple store for diagnostics and service.

Edit: Additional info: This is a mint condition MBP, formatted a mere three months ago to Lion and upgraded to Mountain Lion some weeks ago. It has 4GB of RAM.


Final edit:
I have installed Ubuntu alongside OSX, on the same hard drive. I have also installed all the apps I use on OSX. Ubuntu FLIES, the difference is enormous. Not a single lag, in clicking, rendering, indexing, nothing. Conclusion: OSX just sucks.

Best Answer

Let me explain to you how RAM works. Data is loaded into RAM first, in blocks called "pages". That is called a “Page in”. When a piece of memory is just paged in, it is in Active or Wired Memory. Wired memory is the memory used by the Core System and Active Memory is memory used by other applications.

When a page in Active Memory is no longer being used, it becomes Inactive Memory. The data still stays in RAM because an app may request it later, at which point it becomes Active Memory again.

When your RAM starts to fill up, the oldest pages in the Inactive Memory region are “Paged out”, which means that they are written to the Swap. Your system is slowing down because of this. Your RAM is full, so the system is paging out things to the disk. The disk is slower than the RAM, so your system slows down as data is paged in and out.

You must find out the app(s) using up your RAM with a combination of trial and error and using the Activity Monitor to check the memory usage of each app. Most likely, the problem is a memory leak in an app.