Your system has run out of application memory HUR HUR HUR

I hate this dialog with the fire of a thousand suns.

When this appears, it basically means one (or both) of two things:

  1. Some application went nuts and chewed through all your memory and/or disk space.
  2. macOS got itself into a darkly comical & embarrassing deadlock.

Quitting any of the listed applications is rarely the correct move.  It’s often enough the case that none of them are the root cause, and you can kill all of them if you want, but it won’t fix the problem.

One important thing to clarify first, though, is that this dialog does not necessarily use the term ‘memory’ in the conventional sense – i.e. RAM.  It can also refer to disk space.  Unfortunately it doesn’t bother to distinguish between the two, which is particularly stupid of it since any possible resolution of the issue is highly dependent on which of the two cases it in fact is.

Thank goodness for iStatMenus, though, which in the most recent incident showed that I had ~20 GiB of RAM completely free (not even inactive, actually outright free).  So immediately that rules out what the daft bloody dialog’s actually saying.

The worst thing about all this is when it’s #2 the occurs.  For example, I had Lightroom do a 63-image panorama merge.  As Lightroom is a gross memory pig when doing panorama merging, it consumed something like 40 GiB of memory.  Which caused a bunch of stuff to page to disk.  Which consumed all the disk space.  Which led to that obnoxious dialog.  Which further led to macOS in its infinite fucking wisdom ‘pausing’ (SIGSTOPing) almost all running programs, including evidently whatever daemon actually handles paging.  Thus when Lightroom actually completed the panorama merge and released all that memory, I now had 20 GiB of free memory and the system refused to use any of it to page back in all that memory it’d paged out.  Because it was out of disk space.

The only solution – short of hard rebooting and hoping it resolves itself – was to delete a bunch of files I actually do still want, but which will now have to be recovered from a backup.  Great job macOS, thanks for all your help.

Of course, even once you do that and recover the system from the derpeche mode it put itself into, it won’t actually unpause any of the shit it broke.  You have to do that manually.  It pretends you can do that via that dialog that started the whole thing – assuming you left it open the entire time, blocking your view as you actually help the situation – but that only shows user-visible applications, not all the other system & background processes that it also rudely halted.

So, simple tip for resuming everything:

sudo killall -CONT -m '.'

Elegant, after a fashion.  Though every time, it reminds me that whomever named it ‘killall’ was either not very friendly or not very wise.

Note that the system will probably still be a bit broken in places, as despite what macOS thinks, you can’t just blindly pause random system tasks and not have things get really, really confused.  A reboot is always wise after seeing this dialog, to properly undo its fuckery.

macOS 10.12.2 appears to have brought with it some GPU issues

I run Einstein@Home, using both CPU cores & my GPU.  Other than a few month period where Einstein@Home was issuing broken GPU work units, I’ve been successfully doing this for years, I think.  Longer than I can really remember, in any case.

It appears, however, that 10.12.2 has introduced some serious issues impacting those GPU tasks.  While there’s always been occasional issues with performance while running these GPU tasks – e.g. Amazon streaming video drops frames – I’ve not had any major complaints.

Now, however, I have this:

Screen shot showing massive graphics corruptionThat’s what I get when I render a Nikon NEF file, pretty much anywhere in the system.

The exact symptoms of the issue seem to vary depending on where & what type of NEF file I render – e.g. rendering them in Preview mostly constraints the graphics corruption to Preview, and doesn’t readily lead to the whole system hanging.  Using the Finder for its previews, or Quicklook, however, very quickly leads to massive graphics corruption and, for Nikon D7100 NEFs, quickly hangs the system entirely.  Oddly, Nikon D500 NEFs don’t tend to cause immediate system hangs, but will prevent the system restarting or shutting down – it ends up hung at a black screen, after seemingly closing the window server, with a very consistent pattern of corruption and a frozen mouse cursor.

I never saw this, or anything like it, prior to the 10.12.2 update.  Sigh.

FWIW, the particular work unit in question triggering this right now is:

Screen shot of the Einstein@Home work unit properties dialog

Swift’s String.write(toFile:…) can’t handle tildes

let path = "~/Desktop/sigh.txt"
try "WTF?".write(toFile: path, atomically: true, encoding: .utf8)

Result?  Explode:

Error Domain=NSCocoaErrorDomain Code=4 "The folder “sigh.txt” doesn’t exist." UserInfo={NSFilePath=~/Desktop/sigh.txt, NSUserStringVariant=Folder, NSUnderlyingError=0x1018110b0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

And since there’s no documentation on that write() method, and this is obviously a perfectly reasonable request that can’t sanely yield that bizarre error message, you could be forgiven for having no idea how to fix this.

Long story short, in macOS Sierra at least that write() method happens to be implemented as NSString’s writeToFile:atomically:encoding:error: method.  If you look at the documentation for that method, it states:

path:  The file to which to write the receiver.  If path contains a tilde (~) character, you must expand it with stringByExpandingTildeInPath before invoking this method.

WTF it can’t actually say that in the Swift method’s documentation (or indeed why it has none at all), or why the exception thrown can’t at least give the real reason, or of course WTF it can’t just do the right thing and handle tildes in the path…  I have no idea.  This smells like a combination of laziness, snafu, and poor judgement in carrying over bad behaviours and design flaws from Objective-C.

So instead you have to do:

try "WTF?".write(toFile: (path as NSString).expandingTildeInPath, atomically: true, encoding: .utf8)