Skip to content

Instantly share code, notes, and snippets.

Created January 22, 2014 03:45
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save anonymous/8553178 to your computer and use it in GitHub Desktop.
Save anonymous/8553178 to your computer and use it in GitHub Desktop.
This is a patch (with commentary) that fixes a memory leak in 24.3 for OSX Mavericks (10.9) users who experience excessive resource consumption by distnoted.
From 8ab91751069e391a95151c6716a546b1732ade92 Mon Sep 17 00:00:00 2001
From: JP <twitter:canoeberry>
Date: Sun, 19 Jan 2014 11:58:54 +0000
Subject: [PATCH] partial memleak fix
This patch was created by JP (twitter: @canoeberry) based on a memleak fix by Dirk (emacs committer) below:
https://github.com/mirrors/emacs/commit/57ae6509a3b6a274f89b9caea0284c6156470625
This memory leak is fixed in the trunk as of now and will be in the next official release: 24.4.
However, many of us using cocoa emacs on Mavericks experience random spikes in cpu and excessive resource consumption due to distnoted. This patch potentially fixes emacs-related distnoted issues you may be experiencing.
Steps to use this patch:
You can download a patched version of the source code below:
http://jpayne.net/emacs/
Alternatively, you can patch it yourself:
1. download this patch
2. download emacs
3. apply patch
4. do the configure, make stuff
5. enjoy
curl -O http://ftp.gnu.org/pub/gnu/emacs/emacs-24.3.tar.gz
tar xvfz emacs-24.3.tar.gz
patch -p1 < ../emacs.memory.leak.aka.distnoted.patch.diff
./configure --with-ns --without-x
make bootstrap
make install
open nextstep/Emacs.app
---
src/nsterm.h | 4 ++++
src/nsterm.m | 44 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/src/nsterm.h b/src/nsterm.h
index 806cfcc..aa2a532 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -55,6 +55,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
/* We override sendEvent: as a means to stop/start the event loop */
@interface EmacsApp : NSApplication
{
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
+ BOOL shouldKeepRunning;
+ BOOL isFirst;
+#endif
}
- (void)logNotification: (NSNotification *)notification;
- (void)sendEvent: (NSEvent *)theEvent;
diff --git a/src/nsterm.m b/src/nsterm.m
index a57e744..324f065 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -3373,7 +3373,7 @@ ns_read_socket (struct terminal *terminal, struct input_event *hold_quit)
if ([NSApp modalWindow] != nil)
return -1;
- if (hold_event_q.nr > 0)
+ if (hold_event_q.nr > 0)
{
int i;
for (i = 0; i < hold_event_q.nr; ++i)
@@ -3447,7 +3447,7 @@ ns_select (int nfds, fd_set *readfds, fd_set *writefds,
/* NSTRACE (ns_select); */
- if (hold_event_q.nr > 0)
+ if (hold_event_q.nr > 0)
{
/* We already have events pending. */
kill (0, SIGIO);
@@ -4270,6 +4270,46 @@ ns_term_shutdown (int sig)
@implementation EmacsApp
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
+- (id)init
+{
+ if (self = [super init])
+ self->isFirst = YES;
+
+ return self;
+}
+
+- (void)run
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+
+ if (isFirst) [self finishLaunching];
+ isFirst = NO;
+
+ shouldKeepRunning = YES;
+ do
+ {
+ [pool release];
+ pool = [[NSAutoreleasePool alloc] init];
+
+ NSEvent *event =
+ [self nextEventMatchingMask:NSAnyEventMask
+ untilDate:[NSDate distantFuture]
+ inMode:NSDefaultRunLoopMode
+ dequeue:YES];
+ [self sendEvent:event];
+ [self updateWindows];
+ } while (shouldKeepRunning);
+
+ [pool release];
+}
+
+- (void)stop: (id)sender
+{
+ shouldKeepRunning = NO;
+}
+#endif
+
- (void)logNotification: (NSNotification *)notification
{
const char *name = [[notification name] UTF8String];
--
1.8.4.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment