Skip to content

[MacOS] Missing removeFromSuperlayer causes memory leak #333

Description

@jason-ni

When investigating the multi_window memory leak issue in iced project(iced-rs/iced#3233), I see softbuffer(0.4.8) also has the same leak pattern, that is closing window doesn't release some memory resource. But unlike wgpu, it seems easy to fix in softbuffer. I just added

impl Drop for SendCALayer {
    fn drop(&mut self) {
        unsafe {
            self.0.removeFromSuperlayer();
        }
    }
}

in the cg.rs and then the leak issue solved.

But when I see that in 0.5.0 dev cycle, you are switching to IOSurface for more efficiency, I have concern that it may have similar issue.

Activity

  1. madsmtm commented on Feb 8, 2026

    @madsmtm
    Member

    Yeah that makes sense, we're the "owner" of the layer, but when calling root_layer.addSublayer(layer) we implicitly give ownership to the root layer (so we have to take it back in Drop).

    Do you want to file a PR?


    Why do you think IOSurface would exacerbate this problem though?

  2. added
    bugSomething isn't working
    DS - CoreGraphicsmacOS/iOS/tvOS/watchOS/visionOS backend
    on Feb 8, 2026
  3. jason-ni commented on Feb 8, 2026

    @jason-ni
    Author

    I'm testing your transparency PR branch in my tauri-plugin-iced(https://github.com/jason-ni/tauri-plugin-iced) today. I'd like to wait for the IOSurface PR and transparency PR both being merged to master, then have a test for leakage.
    I have little knowledge about old solution of CALayer vs new IOSurface. But I do see in wgpu backend, the leakage pattern is IOSurface memory is ever increasing. So I have concern that the IOSurface solution may have issue with release memory, too.

  4. madsmtm commented on Feb 8, 2026

    @madsmtm
    Member

    #329 still uses CALayer.

    The reason you're seeing IOSurface leaks is probably because CALayer internally contains those.

  5. added this to the Softbuffer v0.5 milestone on Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DS - CoreGraphicsmacOS/iOS/tvOS/watchOS/visionOS backendbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions