Open live951 opened 4 years ago
@live951 Thanks for the detailed explanation. Can you check if the same issue occurs even if the plugins
option is not used?
Sorry I forgot to mention it in my original report. Yes, the memory leak occurs in the same way even with no plugins, but the memory leak is about half the amount of memory (~0.8MB per 10 mount/unmount cycles vs ~1.6MB with all plugins). Here is the App.js sample code I used:
import "codemirror/lib/codemirror.css";
import "@toast-ui/editor/dist/toastui-editor.css";
import React from "react";
import { Editor } from "@toast-ui/react-editor";
export default class App extends React.Component {
editorRef = React.createRef();
constructor(props) {
super(props);
this.state = {
showEditor: false,
};
}
editorToggle = () => {
this.setState({ showEditor: !this.state.showEditor });
};
removeToggleEditor = () => {
this.editorRef.current.getInstance().remove();
this.editorToggle();
};
render() {
return (
<div className="App">
<button onClick={this.editorToggle}>Toggle Editor</button>
<button onClick={this.removeToggleEditor}>
Remove & Toggle Editor
</button>
{this.state.showEditor ? (
<Editor
usageStatistics={false}
initialValue=""
previewStyle="vertical"
height="600px"
initialEditType="markdown"
useCommandShortcut={true}
ref={this.editorRef}
/>
) : null}
</div>
);
}
}
Hi, can you solve this issue? Github issue
My problem is coming when i want to render data from state. When state data is fetched from an api, then it won't render anything.
See issue live: code sand box
Describe the bug
When using the react-editor component memory does not appear to be freed when the component is unmounted. Every 10 mount/unmount cycles of the Editor appears to consistently increase memory usage on the heap (as reported by Chrome Developer Tools) by approximately 1.6MB even after triggering manual garbage collection.
The only scenario in which memory appears to be properly freed on multiple mount/unmount cycles is when the 'remove' method is called prior to unmounting the react-editor component--but only if no text has been typed into the editor. A single character typed into the Editor, and then calling the remove method before unmounting, results in a memory leak too.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Repeatedly mounting/unmounting the react-editor component, especially if first calling the remove method of the Editor instance, should not result in ever increasing memory usage on the heap (with or without having typed in the Editor).
Desktop (please complete the following information):
Sample code
Here is the App component I used for testing:
Here is index.js: