1

I bought a 32GB MacBook Pro because I teach a software boot camp and need to run several memory intensive apps (video conferencing, ide, chat, browser w/ many tabs, etc...) and my 8GB MBA couldn't keep up.

I soon found that certain apps will use all available space which doesn't solve my problem. I still run into memory issues because certain apps are memory hogs.

Is there some way to specify memory limits on specific apps in MacOS?

  • Can you detail on which specific apps you're talking about? - And how have you assessed that they're memory hogs? – jksoegaard Dec 1 at 15:51
  • Edit in a screenshot of activity monitor showing your memory allocations. Bad software always consumes all available resources. Hopefully you don’t find you had enough ram at 8 GB but let’s dive into your specifics... – bmike Dec 1 at 17:48
  • Yes, more specifics are needed. – benwiggy Dec 2 at 10:50
  • I purposely didn't mention the specific apps because I didn't want to get into a discussion of which browser was best or most memory efficient. @jksoegaard is giving the type of answer I am looking for. – Greg Smith Dec 3 at 14:57
4

Even though you can limit memory for specific apps on macOS, you will not achieve the result you're looking for:

The problem is that when you limit the amount of memory an application can have, this means in practical sense that programs are going to crash when they reach that limit.

So you essentially have the option of having crashing programs or pausing them when they reach the limit. Pausing them is something you have to implement a program to do yourself (not very complex, but you would need some scripting experience or programming experience).

In simple terms, memory limits are not going to help you any more than simply quitting one or two of those hogs when you need to do something else.

UPDATE: In the comments you wrote that you wouldn't mind crashing applications, and that you are an accomplished software engineer, so you would be able to do scripting/programming yourself.

In that case you can implement a memory limit in a variety of ways:

Simplest version

The simplest would be to create a small script that periodically runs ps x -o rss -p $PID | tail -n1 to observe the memory usage of the indicated process ID. This grabs the resident set size, but you might for some odd reason want to use vsz instead of rss to get the vsize instead.

If the observed memory usage is above a threshold you specify, you can then terminate the process. The best way to do this would be to run a command like kill -15 $PID and then after a time run kill -9 $PID. The first is SIGTERM, which tells the process to start closing down by itself. The latter is SIGKILL, which kills the process if it refuses to close down by itself.

Advanced version

A slightly more advanced version is to create a small wrapper program that calls setrlimit() to set a limit on the process, such as for example RLIMIT_DATA (maximum data segment size) or RLIMIT_RSS (maximum resident set size). Afterwards it needs to call execl() or similar to start the application for which you want to limit memory usage.

Note that there's also a possibility of using ulimit instead of rlimit, however my experience is that these limits are not observed on current macOS.

  • 1
    Great general advice. OP might need a follow on question with specifics. – bmike Dec 1 at 17:49
  • Actually, crashing would be acceptable in this case. Can you point me to how I can memory-limit specific apps? I'm an accomplished software engineer so scripting is not a problem. – Greg Smith Dec 2 at 5:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .