ionic-team / ionic-team/capacitor-plugins

Retain Cycle Issue in iOS

Open
#2,462 0 comments 0 reactions 0 assignees View on GitHub
platform: ios
Dominant language
Java
Stars
678
Forks
685
Avg merge
4d 22h
Merged PRs (30d)
3

Description

## Bug Report

The bridge.viewController is not getting released since this plugin hold the strong Reference to the ViewController
on load(), which is leading to retain cycle in iOS .

https://github.com/ionic-team/capacitor-plugins/blob/7.x/screen-orientation/ios/Sources/ScreenOrientationPlugin/ScreenOrientationPlugin.swift

**Inside this class** :

https://github.com/ionic-team/capacitor-plugins/blob/7.x/screen-orientation/ios/Sources/ScreenOrientationPlugin/ScreenOrientation.swift

Please change view controller to weak :

`private weak var capViewController: CAPBridgeViewController?`

### Plugin(s)
Plugin : screen-orientation

https://github.com/ionic-team/capacitor-plugins/blob/main/screen-orientation/ios/Sources/ScreenOrientationPlugin/ScreenOrientation.swift

### Platform(s)
iOS

### Expected Behavior
It should be able to access the bridge.viewController as long as it stays in memory

Or

Please provide option or method to close ViewController safely without memory leaks .

### Additional :

Same issue is observed with `capacitor-barcode-scanner` in load() , it passes viewController reference to `OSBarcodeLib` which strongly holds the viewController

https://github.com/ionic-team/capacitor-barcode-scanner/blob/main/plugin/ios/Sources/CapacitorBarcodeScannerPlugin/CapacitorBarcodeScannerPlugin.swift

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.