File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,12 +57,17 @@ function Graph({
5757
5858 useEffect ( ( ) => {
5959 const handleResize = ( ) => setContainerDim ( ref . current ) ;
60+ let graph = null ;
6061 if ( ref . current ) {
6162 setContainerDim ( ref . current ) ;
6263 window . addEventListener ( 'resize' , handleResize ) ;
63- setInstance ( initialiseNewGraph ( ) ) ;
64+ graph = initialiseNewGraph ( ) ;
65+ setInstance ( graph ) ;
6466 }
65- return ( ) => window . removeEventListener ( 'resize' , handleResize ) ;
67+ return ( ) => {
68+ window . removeEventListener ( 'resize' , handleResize ) ;
69+ if ( graph ) graph . dispose ( ) ;
70+ } ;
6671 } , [ ref ] ) ;
6772
6873 // Update theme when darkMode changes
Original file line number Diff line number Diff line change @@ -15,7 +15,9 @@ const TabBar = ({ superState, dispatcher }) => {
1515 const [ tabToClose , setTabToClose ] = useState ( null ) ;
1616
1717 const closeTab = ( i ) => {
18- localStorageManager . remove ( superState . graphs [ i ] ? superState . graphs [ i ] . graphID : null ) ;
18+ const graph = superState . graphs [ i ] ;
19+ if ( graph && graph . instance ) graph . instance . dispose ( ) ;
20+ localStorageManager . remove ( graph ? graph . graphID : null ) ;
1921 dispatcher ( { type : T . REMOVE_GRAPH , payload : i } ) ;
2022 if ( ! superState . curGraphIndex && superState . graphs . length === 1 ) {
2123 dispatcher ( { type : T . SET_CUR_INSTANCE , payload : null } ) ;
Original file line number Diff line number Diff line change @@ -372,6 +372,15 @@ class CoreGraph {
372372 }
373373 }
374374
375+ dispose ( ) {
376+ if ( ! this . cy ) return ;
377+ if ( this . autoSaveIntervalId !== null ) clearTimeout ( this . autoSaveIntervalId ) ;
378+ this . autoSaveIntervalId = null ;
379+ this . cy . destroy ( ) ;
380+ this . cy = null ;
381+ this . dispatcher = null ;
382+ }
383+
375384 reset ( ) {
376385 this . resetAllComp ( ) ;
377386 this . resetAllAction ( ) ;
You can’t perform that action at this time.
0 commit comments