fix(status-bar): avoid retain cycle between StatusBar and the bridge#2569
Open
puneet25 wants to merge 1 commit into
Open
fix(status-bar): avoid retain cycle between StatusBar and the bridge#2569puneet25 wants to merge 1 commit into
puneet25 wants to merge 1 commit into
Conversation
puneet25
force-pushed
the
fix/status-bar-bridge-retain-cycle
branch
from
July 22, 2026 15:34
683f915 to
57c0270
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes
StatusBar.bridgeaweakreference and updates its call sites to use optional chaining.Why
StatusBarholds a strong reference to the bridge, while the bridge transitively owns theStatusBarinstance:This is a retain cycle, so a
CapacitorBridgethat registers the StatusBar plugin can never be deallocated, and neither can any of its registered plugins. In apps that create and destroy bridges over their lifetime (for example multipleCAPBridgeViewControllers, or Ionic Portals apps that create aPortalUIViewper embedded web view), every discarded bridge leaks its full plugin set and the associated WebKit resources. Memory grows without bound with each create/destroy cycle.Reproduction
CAPBridgeViewController(orPortalUIView) with the StatusBar plugin registered.CapacitorBridge,StatusBarPlugin, and all other registeredCAPPlugininstances remain alive. The graph shows the cycle above.With this change, the same flow releases the bridge and all plugins; instance counts return to baseline after each cycle (verified with Xcode Memory Graph before/after).
Notes
weakback references to the bridge are the established pattern elsewhere, e.g.CAPPlugin.bridgeandWebViewDelegationHandler.bridgein Capacitor core.StatusBarin normal operation (it owns it), so the optional paths only take effect during teardown, where the previous code would have kept the object graph alive instead.