Ashok R
Ashok R

Reputation: 20786

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

Upvotes: 3

Views: 2062

Answers (1)

thomas li
thomas li

Reputation: 11

add prop

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

Upvotes: 1

Related Questions