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

Sharing.PassthroughRelay memory leak #137

Open
3 tasks done
denysdanyliukboosters opened this issue Mar 24, 2025 · 1 comment
Open
3 tasks done

Sharing.PassthroughRelay memory leak #137

denysdanyliukboosters opened this issue Mar 24, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@denysdanyliukboosters
Copy link

denysdanyliukboosters commented Mar 24, 2025

Description

I discovered a memory leak issue with the @Shared component. Creating @Shared within a function creates numerous objects that are never deallocated. I have attached a simple code example that reproduces the issue by repeatedly tapping on a view, which creates new instances of @Shared.

Notably, this leak began appearing after version 2.1.1 and appears to be linked to this pull request.

Below is the Xcode memory graph after tapping five times:
Image

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

No response

Actual behavior

No response

Reproducing project

import SwiftUI
import Sharing

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
        .padding()
        .onTapGesture {
            @Shared(.foo) var foo
            print("Tapped")
        }
    }
}

#Preview {
    ContentView()
}

extension SharedReaderKey where Self == AppStorageKey<Bool>.Default {
    public static var foo: Self {
        Self[
            .appStorage("foo"),
            default: false
        ]
    }
}

Sharing version information

2.1.1 - 2.3.3

Destination operating system

iOS 18

Xcode version information

16.2

Swift Compiler version information

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
@denysdanyliukboosters denysdanyliukboosters added the bug Something isn't working label Mar 24, 2025
@denysdanyliukboosters
Copy link
Author

What do you think about this issue? Is it possible to resolve it? If so, could you please provide an estimated timeline for the fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant