/* chart_tv_lifecycle.js — dispose Lightweight Charts / DOM / listeners */ /** 释放 Lightweight Charts 实例、DOM 与全局事件,避免自动刷新内存泄漏 */ function disposeTradingViewCharts() { try { if (window._tvInitCleanups && Array.isArray(window._tvInitCleanups)) { window._tvInitCleanups.forEach(function (fn) { try { fn(); } catch (e) {} }); } window._tvInitCleanups = []; if (window._bindSyncCleanups && Array.isArray(window._bindSyncCleanups)) { window._bindSyncCleanups.forEach(function (fn) { try { fn(); } catch (e) {} }); } window._bindSyncCleanups = []; if (window._tooltipCleanups && Array.isArray(window._tooltipCleanups)) { window._tooltipCleanups.forEach(function (fn) { try { fn(); } catch (e) {} }); } window._tooltipCleanups = []; document.querySelectorAll( '.volume-crosshair-line, .atr-crosshair-line, .macd-crosshair-line, .chanmacd-crosshair-line' ).forEach(function (el) { try { el.remove(); } catch (e) {} }); if (typeof clearEMA52Series === 'function') { try { clearEMA52Series(); } catch (e) {} } if (tvWidget) { ['mainChart', 'volumeChart', 'macdChart', 'chanMacdChart', 'atrChart'].forEach(function (key) { try { if (tvWidget[key] && typeof tvWidget[key].remove === 'function') { tvWidget[key].remove(); } } catch (e) {} tvWidget[key] = null; }); if (tvWidget.state) { tvWidget.state.isInitialized = false; } } var chartRoot = document.getElementById('tradingview_chart'); if (chartRoot) { // 重建前救出 Cycle Summary,避免 innerHTML 清空时被销毁 var summaryEl = document.getElementById('wyckoffCycleSummary'); var chartHost = chartRoot.parentElement; if (summaryEl && chartRoot.contains(summaryEl) && chartHost) { chartHost.appendChild(summaryEl); } chartRoot.innerHTML = ''; } } catch (e) { console.warn('disposeTradingViewCharts 失败(可忽略):', e); } }