From 3c27d4f4bc4d5610854cfaaa19ea35803edd87f2 Mon Sep 17 00:00:00 2001 From: Jonathan del Strother Date: Wed, 11 Jul 2012 12:45:08 +0100 Subject: [PATCH] Force autorelease pool flush after an FSEvent The top-level autorelease pool only gets cleared out on application events, not including things like the FSEvent handler. If MacVim is in the background while ~/.vim changes, autoreleased objects will carry on building up until the users switches back to it, resulting in a high memory water mark and a lot of needless deallocs. See http://www.mikeash.com/pyblog/more-fun-with-autorelease.html --- src/MacVim/MMAppController.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/MacVim/MMAppController.m b/src/MacVim/MMAppController.m index 4fc0c8d391..89a37f0aec 100644 --- a/src/MacVim/MMAppController.m +++ b/src/MacVim/MMAppController.m @@ -1854,6 +1854,21 @@ fsEventCallback(ConstFSEventStreamRef streamRef, preloadPid = [self launchVimProcessWithArguments: [NSArray arrayWithObject:@"--mmwaitforack"] workingDirectory:nil]; + + // This method is kicked off via FSEvents, so if MacVim is in the + // background, the runloop won't bother flushing the autorelease pool. + // Triggering an NSEvent works around this. + // http://www.mikeash.com/pyblog/more-fun-with-autorelease.html + NSEvent* event = [NSEvent otherEventWithType:NSApplicationDefined + location:NSZeroPoint + modifierFlags:0 + timestamp:0 + windowNumber:0 + context:nil + subtype:0 + data1:0 + data2:0]; + [NSApp postEvent:event atStart:NO]; } - (int)maxPreloadCacheSize