Prerequisites
Ionic Framework Version
Current Behavior
When a controller modal is dismissed, it's contents are detached from the DOM but are unable to me garbage collected. This represents a resource leak, and repeated opening/closing of a modal like this will eventually lead to the app being killed by the operating system.
Expected Behavior
When a modal is dismissed, all resources associated it should be freed.
Steps to Reproduce
- Go to the documentation page for controller modals:
https://ionicframework.com/docs/usage/v6/modal/controller/demo.html?ionic:mode=ios
- Open Chrome Devtools "Performance Monitor" tab
- Take a Heap Snapshot (Memory > Record button)
- Repeatedly open and close the modal
- Watch the Performance Monitor tab's "DOM Nodes" number increase indefinitely
- Force manual GC (trash icon in the Memory tab) - note the DOM nodes do not reduce
- Take another Heap Snapshot and compare. You will see 100s of Detached Elements
A video of me doing these steps:
https://drive.google.com/file/d/1ciQxC1xSa_aiyrA2OfEIJCjXHJH_sBhx/view?usp=sharing
Code Reproduction URL
https://ionicframework.com/docs/usage/v6/modal/controller/demo.html?ionic:mode=ios
Ionic Info
Ionic:
Ionic CLI : 6.20.6 (/Users/joewoodhouse/.nvm/versions/node/v16.14.2/lib/node_modules/@ionic/cli)
Capacitor:
Capacitor CLI : 4.6.2
@capacitor/android : 4.6.3
@capacitor/core : 4.6.3
@capacitor/ios : 4.6.3
Utility:
cordova-res : not installed globally
native-run : 1.7.1
System:
NodeJS : v16.14.2 (/Users/joewoodhouse/.nvm/versions/node/v16.14.2/bin/node)
npm : 8.7.0
OS : macOS
Additional Information
I believe these issues are probably related to an underlying Stencil problem, but I haven't been able to track it down. As part of my investigation I've found other issues in stencil namely
stenciljs/core#4070
stenciljs/core#4067
There are known issues around how Stencils runtime and VDOM implementation hold strong (rather than weak) references to DOM nodes that are probably also contributing to this issue.
Whilst obviously for a documentation website this isn't a problem, for us this represents a major problem as we have a mobile application that displays 100s of modals during the course of the apps lifetime. This bug means that are users regularly experience crashes after a moderate amount of use, simply because the operating system kills the WebView due to it using too many resources. Using inline modals could be an option for us but it would require a major refactor.
Prerequisites
Ionic Framework Version
Current Behavior
When a controller modal is dismissed, it's contents are detached from the DOM but are unable to me garbage collected. This represents a resource leak, and repeated opening/closing of a modal like this will eventually lead to the app being killed by the operating system.
Expected Behavior
When a modal is dismissed, all resources associated it should be freed.
Steps to Reproduce
https://ionicframework.com/docs/usage/v6/modal/controller/demo.html?ionic:mode=ios
A video of me doing these steps:
https://drive.google.com/file/d/1ciQxC1xSa_aiyrA2OfEIJCjXHJH_sBhx/view?usp=sharing
Code Reproduction URL
https://ionicframework.com/docs/usage/v6/modal/controller/demo.html?ionic:mode=ios
Ionic Info
Ionic:
Ionic CLI : 6.20.6 (/Users/joewoodhouse/.nvm/versions/node/v16.14.2/lib/node_modules/@ionic/cli)
Capacitor:
Capacitor CLI : 4.6.2
@capacitor/android : 4.6.3
@capacitor/core : 4.6.3
@capacitor/ios : 4.6.3
Utility:
cordova-res : not installed globally
native-run : 1.7.1
System:
NodeJS : v16.14.2 (/Users/joewoodhouse/.nvm/versions/node/v16.14.2/bin/node)
npm : 8.7.0
OS : macOS
Additional Information
I believe these issues are probably related to an underlying Stencil problem, but I haven't been able to track it down. As part of my investigation I've found other issues in stencil namely
stenciljs/core#4070
stenciljs/core#4067
There are known issues around how Stencils runtime and VDOM implementation hold strong (rather than weak) references to DOM nodes that are probably also contributing to this issue.
Whilst obviously for a documentation website this isn't a problem, for us this represents a major problem as we have a mobile application that displays 100s of modals during the course of the apps lifetime. This bug means that are users regularly experience crashes after a moderate amount of use, simply because the operating system kills the WebView due to it using too many resources. Using inline modals could be an option for us but it would require a major refactor.