[MacOS] Fix memory management (#1342)
* macOS, Reduce memory usage * macOS, Fix memory leak
This commit is contained in:
parent
e4451d6786
commit
fa7a3025ec
2 changed files with 11 additions and 2 deletions
|
|
@ -11,7 +11,11 @@ use std::{
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use cocoa::{appkit::NSApp, base::nil, foundation::NSString};
|
use cocoa::{
|
||||||
|
appkit::NSApp,
|
||||||
|
base::nil,
|
||||||
|
foundation::{NSAutoreleasePool, NSString},
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
event::{Event, StartCause},
|
event::{Event, StartCause},
|
||||||
|
|
@ -277,6 +281,8 @@ impl AppState {
|
||||||
unsafe {
|
unsafe {
|
||||||
let _: () = msg_send![NSApp(), stop: nil];
|
let _: () = msg_send![NSApp(), stop: nil];
|
||||||
|
|
||||||
|
let pool = NSAutoreleasePool::new(nil);
|
||||||
|
|
||||||
let windows: *const Object = msg_send![NSApp(), windows];
|
let windows: *const Object = msg_send![NSApp(), windows];
|
||||||
let window: *const Object = msg_send![windows, objectAtIndex:0];
|
let window: *const Object = msg_send![windows, objectAtIndex:0];
|
||||||
assert_ne!(window, nil);
|
assert_ne!(window, nil);
|
||||||
|
|
@ -292,6 +298,8 @@ impl AppState {
|
||||||
let _: () = msg_send![window, setTitle: some_unique_title];
|
let _: () = msg_send![window, setTitle: some_unique_title];
|
||||||
// And restore it.
|
// And restore it.
|
||||||
let _: () = msg_send![window, setTitle: title];
|
let _: () = msg_send![window, setTitle: title];
|
||||||
|
|
||||||
|
pool.drain();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
HANDLER.update_start_time();
|
HANDLER.update_start_time();
|
||||||
|
|
|
||||||
|
|
@ -95,12 +95,13 @@ impl<T> EventLoop<T> {
|
||||||
F: FnMut(Event<T>, &RootWindowTarget<T>, &mut ControlFlow),
|
F: FnMut(Event<T>, &RootWindowTarget<T>, &mut ControlFlow),
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
let _pool = NSAutoreleasePool::new(nil);
|
let pool = NSAutoreleasePool::new(nil);
|
||||||
let app = NSApp();
|
let app = NSApp();
|
||||||
assert_ne!(app, nil);
|
assert_ne!(app, nil);
|
||||||
AppState::set_callback(callback, Rc::clone(&self.window_target));
|
AppState::set_callback(callback, Rc::clone(&self.window_target));
|
||||||
let _: () = msg_send![app, run];
|
let _: () = msg_send![app, run];
|
||||||
AppState::exit();
|
AppState::exit();
|
||||||
|
pool.drain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue