From 08c311839f9c65faa358b0540a3ff6b2eb19ff14 Mon Sep 17 00:00:00 2001 From: Felix Kaaman Date: Wed, 2 Mar 2016 16:40:19 +0100 Subject: Fix memory leak while creating NSEvent and swapping buffers (Fixes #514) --- src/api/cocoa/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs index abcd735..ca77ce9 100644 --- a/src/api/cocoa/mod.rs +++ b/src/api/cocoa/mod.rs @@ -224,12 +224,16 @@ impl<'a> Iterator for PollEventsIterator<'a> { let event: Option; unsafe { + let pool = NSAutoreleasePool::new(nil); + let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_( NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantPast(nil), NSDefaultRunLoopMode, YES); event = NSEventToEvent(self.window, nsevent); + + let _: () = msg_send![pool, release]; } event } @@ -249,12 +253,16 @@ impl<'a> Iterator for WaitEventsIterator<'a> { let event: Option; unsafe { + let pool = NSAutoreleasePool::new(nil); + let nsevent = NSApp().nextEventMatchingMask_untilDate_inMode_dequeue_( NSAnyEventMask.bits() | NSEventMaskPressure.bits(), NSDate::distantFuture(nil), NSDefaultRunLoopMode, YES); event = NSEventToEvent(self.window, nsevent); + + let _: () = msg_send![pool, release]; } if event.is_none() { @@ -747,7 +755,11 @@ impl GlContext for Window { #[inline] fn swap_buffers(&self) -> Result<(), ContextError> { - unsafe { self.context.flushBuffer(); } + unsafe { + let pool = NSAutoreleasePool::new(nil); + self.context.flushBuffer(); + let _: () = msg_send![pool, release]; + } Ok(()) } -- cgit v1.2.3