I wrote class component in my current working project and faced issues javascript heap out of memory then I found of componentWillUnmount
method I used in whole project. Actually it is useful but there some components where I don't have anything to clear e.g: async calls, timeouts etc. Do I need to write componentWillUnmount there?
Also I'm using varibles in main scope making them null
in this method is it correct?
posting an example:
var exampleOne = [];
var exampleTwo;
export class Demo extends Component {
constructor(props) {
super(props);
this.state = {
someState: null
};
}
componentWillUnmount() {
exampleOne = null;
exampleTwo = null;
}
render() {
return <div>Hello World {this.state.someState}</div>;
}
}
export default Demo;