sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Investigate strong references after SDK close

Open philprime opened this issue 6 months ago • 1 comments

Description

During development I noticed that when closing the SDK using the Close SDK button in the iOS sample app, there are still strong references internally which are not cleaned up properly.

This was noticed by the following warning, which is also user-facing:

Image

This is actually caused by session replay not cleaning up the background processing, with the scope being already discarded, causing it to create and configure a new scope, which then accesses the UIWindow from the background thread.

https://github.com/getsentry/sentry-cocoa/blob/603fec8f5dcd6e209a79e2dfa4f7089f01cc5d20/Sources/Sentry/SentryCrashWrapper.m#L187-L194

Furthermore the memory graph after the close still shows a lot of non-deallocated instances of the SDK:

Image

philprime avatar Jun 10 '25 15:06 philprime

An initial investigation has show that some of these references might actually be false positives as the dependency container gets recreated in reset rather than deallocated.

Image

In addition I did find classes which have their own singleton, are not deallocated when calling SentrySDK.close(), e.g. the SentryGlobalEventProcessor. This will require refactoring to move them to the dependency container.

philprime avatar Jun 17 '25 14:06 philprime