Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macos memory leaks #2727

Closed
wants to merge 2 commits into from
Closed

Fix macos memory leaks #2727

wants to merge 2 commits into from

Conversation

madsmtm
Copy link
Member

@madsmtm madsmtm commented Mar 9, 2023

Fixes #2722 without having to do the objc2 update.

  • Tested on all platforms changed
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

@madsmtm madsmtm added B - bug Dang, that shouldn't have happened DS - macos labels Mar 9, 2023
@lunixbochs
Copy link
Contributor

This crashes for me with the examples/window.rs example, if you drop the window:

Crashes every few runs (dropping one window):

#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
    event::{Event, WindowEvent},
    event_loop::EventLoop,
    window::WindowBuilder,
};

fn main() {
    SimpleLogger::new().init().unwrap();
    let event_loop = EventLoop::new();

    let mut window: Option<winit::window::Window> = None;
    window.replace(WindowBuilder::new()
        .with_title("A fantastic window!")
        .with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0))
        .build(&event_loop)
        .unwrap());

    event_loop.run(move |event, window_target, control_flow| {
        let event_loop = window_target;
        control_flow.set_wait();
        println!("{event:?}");

        match event {
            Event::MainEventsCleared => {
                window.take();
            }
            _ => (),
        }
    });
}

Crashes every run (repeatedly opening and closing a window):

#![allow(clippy::single_match)]

use simple_logger::SimpleLogger;
use winit::{
    event::{Event, WindowEvent},
    event_loop::EventLoop,
    window::WindowBuilder,
};

fn main() {
    SimpleLogger::new().init().unwrap();
    let event_loop = EventLoop::new();

    let mut window: Option<winit::window::Window> = None;

    event_loop.run(move |event, window_target, control_flow| {
        let event_loop = window_target;
        control_flow.set_wait();
        println!("{event:?}");

        match event {
            Event::MainEventsCleared => {
                window.replace(WindowBuilder::new()
                    .with_title("A fantastic window!")
                    .with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0))
                    .build(&event_loop)
                    .unwrap());
            }
            _ => (),
        }
    });
}

@madsmtm
Copy link
Member Author

madsmtm commented Mar 13, 2023

Yeah, I investigated it and found out that this approach cannot be used (the Box that DeallocHelper internally uses is deallocated at the wrong time), so we'll have to do something else instead.

@madsmtm madsmtm closed this Mar 13, 2023
@madsmtm
Copy link
Member Author

madsmtm commented Mar 13, 2023

Replaced by #2739

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened B - regression DS - macos
Development

Successfully merging this pull request may close these issues.

Regression in 0.28 - NSWindow leaks on macOS
3 participants