Repository navigation
Commit fb07ea3
authored
Fix TextInput state retain chain in AndroidTextInputShadowNode
Summary:
`AndroidTextInputShadowNode::getAttributedString` builds the fragment for a controlled `value` with `parentShadowView = ShadowView(*this)`. A full `ShadowView` carries the node's current `state` and `props`. `updateStateIfNeeded` stores that attributed string in the next `AndroidTextInputState` (`reactTreeAttributedString`), so every new state keeps the previous state (and props) alive. The chain grows by one link per value change for as long as the input stays mounted.
Two effects:
- Memory: native heap grows with every change to a controlled `TextInput` and is only released on unmount.
- Crash: on unmount the whole chain is destroyed recursively on the JS thread. Long chains overflow the stack, and crash stacks repeat `State → AttributedString → Fragment → ShadowView → State` dozens of times before ending in a SIGSEGV in `~AndroidTextInputState()`.
D94267721 fixed the same retain chain for iOS/macOS by adding `shadowViewFromShadowNode()` in `BaseTextInputShadowNode.h`. `AndroidTextInputShadowNode` does not inherit from `BaseTextInputShadowNode`, so Android still had the bug.
This change clears `props` and `state` on the parent `ShadowView` before storing it in the fragment, mirroring the iOS fix. On Android, `parentShadowView` is only read for `tag`, `componentHandle` and `layoutMetrics`. Its `state` and `props` are never read.
## Changelog:
[Android] [Fixed] - Fix memory leak in TextInput: each state retained the previous one, which could overflow the stack on unmount
Differential Revision: D131297146
Pull Request resolved: #599801 parent 2387ec5 commit fb07ea3
1 file changed
Lines changed: 6 additions & 1 deletion
File tree
- packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
193 | 198 | | |
194 | 199 | | |
195 | 200 | | |
| |||
0 commit comments