37
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

purgeコマンドでMacのメモリを確保する

Last updated at Posted at 2016-06-26

Macのメモリが足りなくなって困っていたので、対処としてpurgeコマンドを使ってみました。

環境

$ sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.11.4
BuildVersion:	15E65

purgeコマンド

$ man purge | cat

purge(8)                  BSD System Manager's Manual                 purge(8)

NAME
     purge -- force disk cache to be purged (flushed and emptied)

SYNOPSIS
     purge

DESCRIPTION
     Purge can be used to approximate initial boot conditions with a cold disk
     buffer cache for performance analysis. It does not affect anonymous mem-
     ory that has been allocated through malloc, vm_allocate, etc.

SEE ALSO
     sync(8), malloc(3)

                              September 20, 2005

force disk cache to be purged

ディスクキャッシュを一掃してくれるそうです。

実際にターミナルを開いて sudo purge すると、使用済みメモリが1GBほど減ったのを確認できました。

$ vm_stat | grep free
Pages free:                               73862.
$ sudo purge
$ vm_stat | grep free
Pages free:                              323166.

purgeコマンドをアプリケーションにする

スクリプトエディタで下記を貼り付け、JXA(JavaScript for Automation)でアプリケーション化できます。

var app = Application.currentApplication();
app.includeStandardAdditions = true;
app.doShellScript("purge", {administratorPrivileges:true, withPrompt:"$ sudo purge"});
app.displayDialog("purged");

参考

37
43
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?