에디터에서 사용한 리소르를 정리하는 함수로 이벤트와 참조를 제거해 메모리 누수를 방지합니다.

페이지를 떠날 때(onBeforeUnload) 자동으로 실행됩니다.


싱글페이지 어플리케이션(SPA)에서는 `destroy` 함수가 컴포넌트를 더 이상 사용하지 않을 때 실행되어야 합니다.

주로 페이지 이동이나 컴포넌트 언마운트 시 호출하여 이벤트리스너와 참조를 해제함으로써 메모리 누수를 방지합니다.


Example:

// react 예제 (unmount 시 destroy 호출)
import { useEffect } from 'react';
import Editor from './Editor'; // 가상의 에디터 모듈

const MyEditorComponent = () => {
  let editorInstance;

  // 에디터 초기화
  useEffect(() => {
    editorInstance = new Editor();
    editorInstance.initialize();

    // 페이지를 떠나거나 컴포넌트가 언마운트될 때 destroy 함수를 호출해야 합니다
    return () => {
      if (editorInstance) {
        editorInstance.destroy();
        editorInstance = null;
      }
    };
  }, []);

  return <div id="editor-container"></div>;
};

export default MyEditorComponent;