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
This commit is contained in:
Jonathan del Strother
2012-07-11 12:45:08 +01:00
committed by Bjorn Winckler
parent 655ced19ea
commit 3c27d4f4bc
+15
View File
@@ -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