Tech Tip: Purging inactive memory in macOS Mavericks through Sierra
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac OS X
Published On: August 16, 2017
When 4D allocates memory it simply requests memory from the operating systems memory manager. When it is done with the memory it is simply released back to the operating system's memory manager.
Older versions of macOS would label this memory "Inactive" allowing it to be converted back to Active if the application is relaunched. Apple described this "Inactive" memory pool as:
Inactive: This information is in RAM but isn't actively being used, though it was recently used. For example, if you've been using Mail and then quit it, the RAM that Mail was using is marked as Inactive memory. Inactive memory is available for use by another application, just like free memory. However, if you open Mail before its inactive memory is used by a different application, Mail will open quicker because its inactive memory is converted to active memory, instead of loading it from the slower drive. |
Newer versions of macOS no longer call this Inactive memory, but now use a concept of "File Cache" (or "Cache" or "Cached Files" depending on the macOS version used). Apple describes this "Cache" memory pool as:
Cached Files: Memory that was recently used by apps and is now available for use by other apps. For example, if you've been using Mail and then quit Mail, the RAM that Mail was using becomes part of the memory used by cached files, which then becomes available to other apps. If you open Mail again before its cached-files memory is used (overwritten) by another app, Mail opens more quickly because that memory is quickly converted back to app memory without having to load its contents from your startup drive. |
In both situations listed above, the inactive/cache memory pools are supposed to be usable by other applications just like it was free memory... However the macOS memory manager will sometimes choose to swap memory to disk instead of reallocating memory out of these inactive/cache pools. It is therefore suggested to use the purge command to clear out the file cache and inactive memory pools, turning them into free memory that is directly useable by applications.
As of 10.9.x, the purge command requires elevated privileges. Elevated privileges can be obtained at the command line by using sudo but obtaining elevated privileges within LAUNCH EXTENRAL PROCESS is not simple.
One approach to overcome this is to launch 4D with elevated privileges; however that means that the entire application is running with elevated privileges, which may not be desired.
Another approach is to use the purge plugin from Keisuke Miyako, which installs a helpertool that asks for authorization. The helpertool is then able to perform the purge upon subsequent requests without needing to ask for authorization again.
See Also: