From 21a6fbaeb575777198d2403c2fe76a409f1b1de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sidney=20San=20Mart=C3=ADn?= Date: Wed, 24 Mar 2021 11:41:43 -0400 Subject: [PATCH] Don't rely on NSCache to retain newly-created lines. When there's memory pressure, the cache just drops the line immediately. Fixes #1164. --- src/MacVim/MMCoreTextView.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index cca0790330..19f5bfe1ed 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -1138,7 +1138,7 @@ - (CTLineRef)lineForCharacterString:(NSString *)string if (!strCache){ strCache = characterLines[key] = [[[NSCache alloc] init] autorelease]; } - CTLineRef line = (CTLineRef)[strCache objectForKey:string]; + CTLineRef line = (CTLineRef)[[strCache objectForKey:string] retain]; if (!line) { NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:string @@ -1150,9 +1150,8 @@ - (CTLineRef)lineForCharacterString:(NSString *)string line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString); [attrString release]; [strCache setObject:(id)line forKey:[[string copy] autorelease]]; - CFRelease(line); } - return line; + return (CTLineRef)[(id)line autorelease]; } @end // MMCoreTextView (Private)