Use @autoreleasepool to avoid accumulating objects

This commit is contained in:
David Capello 2017-01-10 12:24:22 -03:00
parent 0b37d23c37
commit 5ba071e760
2 changed files with 46 additions and 42 deletions

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2015-2016 David Capello // Copyright (C) 2015-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -19,6 +19,7 @@ void OSXEventQueue::getEvent(Event& ev, bool canWait)
{ {
ev.setType(Event::None); ev.setType(Event::None);
@autoreleasepool {
retry:; retry:;
NSApplication* app = [NSApplication sharedApplication]; NSApplication* app = [NSApplication sharedApplication];
if (!app) if (!app)
@ -56,6 +57,7 @@ retry:;
} }
} }
} }
}
void OSXEventQueue::queueEvent(const Event& ev) void OSXEventQueue::queueEvent(const Event& ev)
{ {

View File

@ -1,5 +1,5 @@
// SHE library // SHE library
// Copyright (C) 2012-2016 David Capello // Copyright (C) 2012-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information. // Read LICENSE.txt for more information.
@ -113,6 +113,7 @@ public:
} }
void updateWindow(const gfx::Rect& bounds) { void updateWindow(const gfx::Rect& bounds) {
@autoreleasepool {
int scale = this->scale(); int scale = this->scale();
NSView* view = m_window.contentView; NSView* view = m_window.contentView;
[view setNeedsDisplayInRect: [view setNeedsDisplayInRect:
@ -122,6 +123,7 @@ public:
bounds.h*scale)]; bounds.h*scale)];
[view displayIfNeeded]; [view displayIfNeeded];
} }
}
void setTranslateDeadKeys(bool state) { void setTranslateDeadKeys(bool state) {
OSXView* view = (OSXView*)m_window.contentView; OSXView* view = (OSXView*)m_window.contentView;
@ -304,7 +306,7 @@ private:
return; return;
bitmap.lockPixels(); bitmap.lockPixels();
{ @autoreleasepool {
NSGraphicsContext* gc = [NSGraphicsContext currentContext]; NSGraphicsContext* gc = [NSGraphicsContext currentContext];
CGContextRef cg = (CGContextRef)[gc graphicsPort]; CGContextRef cg = (CGContextRef)[gc graphicsPort];
CGColorSpaceRef colorSpace = CGDisplayCopyColorSpace(CGMainDisplayID()); CGColorSpaceRef colorSpace = CGDisplayCopyColorSpace(CGMainDisplayID());