Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to release react-native webview memory

I am loading Three.JS Model using WebView in my react-native app. After loading the Model the memory is increased.

Now when i tap on button i want to deallocate the webView Component and want release the memory.

OR when i go to next screen i would like to release the memory.

Below is my code.

{this.state.showWebview &&
        <WebView
            ref={(wbref) => {
              this.webview = wbref;
            }}
            style={styles.middleview}
            source={{
              uri: this.state.showWebview && this.props.isCurrentScreenOnTop
              ? '3DMODEL/vechicle.html'
              : null,
            }}
            onLoadStart={this.onLoadStart}
            onLoad={this.onLoad}
            onLoadEnd={this.onLoadEnd}
            onError={this.onError}
            renderError={this.renderError}
            onMessage={this.handleMessageFromBuilder}
            cacheEnabled={false}
            cookiesEnabled={false}
        />}

componentWillUnmount() {
    this.webview = null;
}

Below is the memory graph.

enter image description here

like image 719
Ashok R Avatar asked Jan 29 '26 20:01

Ashok R


1 Answers

add prop

useWebkit={true} and the memory will allocate a little.

like image 131
thomas li Avatar answered Feb 01 '26 17:02

thomas li