It's not working correctly. As soon as inactive RAM is used up apps run like crap. They can't dig into the inactive RAM and the whole system comes to a crawl trying to speculate on what will happen next and failing to deliver in the present. Design what you are I guess.
This is not intended as a tutorial of memory management in modern operating systems. Just enough to point the reader in the right direction.
"Inactive RAM" is perhaps not the best title. Every modern OS (including MacOS) uses the nearly the same virtual memory / real memory management principles.
Let's assume the computer was just rebooted. The real memory is not constrained; not under pressure using MacOS terms.
When an application (let's use MS Word) starts, MacOS will create a process (also known as virtual address space) and begin to allocate pages in real memory which contain code and data.
When MS Word is closed, MacOS will mark most of the pages in real memory as Inactive. If MS Word is open again, almost all pages still reside in real memory and the application will open very quickly. That's the real purpose of Inactive RAM. Think of it as a general purpose cache managed by MacOS.
Free RAM (real memory to be precise) is wasted memory. So Inactive RAM is "good for you".
Growth of Inactive RAM is not a memory leak, although a rare bug could exist if MacOS cannot invalidate Inactive pages and make them available for new processes. This would be a VERY rare bug.
When real memory is constrained, MacOS - just like other modern operating systems - will perform additional activities.
One of the first steps: find new pages in real memory.
- Invalidate pages in Inactive RAM (since it's just a cache)
- Examine pages in every active process and look for pages not recently referenced; mark these pages as Eligible for Page Out. This is also known as Working Set Size Trim. These pages in real memory will be paged out (or swapped) to the swap file and become available again
Memory leak is a completely different problem. In short - memory leak is created when program logic continues to allocate new pages and retains pointers to these pages. The operating system cannot invalidate these pages because they are a part of the address space while not being referenced. The end result is a misleading message that the system is out memory.
In practice, this is what happens during a memory leak. Let's create a string and add a new character continuously: "leak+leak+leak" ...
- New pages are being created and paged-in
- Since the string is not referenced, OS marks these pages as Eligible for Page Out (trimmed)
- Eventually, these pages are need by other active applications and paged-out (swapped): moved to the swap file
- When the swap file is full, the dreaded "System out of memory" message is displayed