launchdarkly / ios-client-sdk

LaunchDarkly Client-side SDK for iOS (Swift and Obj-C)
https://docs.launchdarkly.com/sdk/client-side/ios
Other
68 stars 84 forks source link

Memory leak on `LDSwiftEventSource` when LD reconnects #258

Closed fbarbat closed 2 years ago

fbarbat commented 2 years ago

Is this a support request? No

Describe the bug Memory leak on LDSwiftEventSource when LD reconnects

To reproduce 1 - Start from Xcode a macOS app that uses LD 2 - Pause on a breakpoint for some minutes so LD connection to server side is lost 3 - Resume the execution. LD will try to reconnect by calling LDSwiftEventSource.connect 4 - Inspect the memory 5 - There will be many leaked objects and if you navigate back to the source objects retaining them you will see: Screen Shot 2021-10-12 at 19 20 51

Expected behavior When using the memory inspector, there shouldn't be any memory leaks that point to LD retain cycle. The ConnectionHandler created in LDSwiftEventSource.connect shouldn't retain self.

Logs .

SDK version 5.4.3

Language version, developer tools Xcode 13, Swift

OS/platform macOS

Additional context Note this is a macOS app using this SDK.

fbarbat commented 2 years ago

I just realized LDSwiftEventSource is on a dependent project and that there was a PR to fix it there https://github.com/launchdarkly/swift-eventsource/pull/23/files. Leaving this issue open because it needs to be fixed there but also the dependency needs to be updated here.

gwhelanLD commented 2 years ago

Hi @fbarbat,

Thanks for filing this issue. We're actively evaluating the PR in the swift-eventsource repo now and should have it merged (or a similar fix) and released soon.

I agree that leaving this issue open until the SDK has published a version dependent on a version of LDSwiftEventSource with the fix makes sense.

Thanks, @gwhelanLD

gwhelanLD commented 2 years ago

Hi @fbarbat,

The https://github.com/launchdarkly/ios-client-sdk/releases/tag/5.4.4 is now available and should resolve this leak. Thanks for pointing out this issue and contributing towards a fix for LDSwiftEventSource.

Thanks, @gwhelanLD