ios-branch-sdk-spm icon indicating copy to clipboard operation
ios-branch-sdk-spm copied to clipboard

Memory leak on initSession

Open KeiroMidori opened this issue 8 months ago • 3 comments
trafficstars

BranchLeak.trace.zip

Describe the bug

When a Branch object gets instantiated whether through the app's delegate initSession call or when tracking an event, a memory leak is created. It's 100% reproducible and goes away as soon as I remove anything that creates a Branch instance.

Image

Steps to reproduce

  1. Create a fresh project (e.g: new SwiftUI app) and import the Branch SDK via SPM
  2. Init a Branch instance
  3. Run the app on the simulator or a real device
  4. Wait for a few minutes for the leak to show up (for me the leak shows up after around 2.5 minutes)
import SwiftUI
import BranchSDK

class AppDelegate: NSObject, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        Branch.getInstance().initSession(launchOptions: launchOptions) { (params, error) in
            print("Branch initSession completed")
        }
        return true
    }
}

@main
struct MemoryLeakExampleApp: App {
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate

    var body: some Scene {
        WindowGroup {
            ContentView()
                .onOpenURL(perform: { url in
                    Branch.getInstance().handleDeepLink(url)
                })
        }
    }
}

Expected behavior

I would expect no memory leak

SDK Version

3.10.0

XCode Version

16.2.0

Device

iPhone 13 Pro Max

OS

iOS 18.3.1

Additional Information/Context

No response

KeiroMidori avatar Mar 14 '25 00:03 KeiroMidori