From 1ec0a8a611ac6bb6cbabafe1fafa10d7c06c4a37 Mon Sep 17 00:00:00 2001 From: ISA Date: Fri, 6 Jun 2025 11:05:33 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20automatische=20Heap-=C3=9Cberwachung=20?= =?UTF-8?q?integriert=20mit=20Reload=20bei=20=C3=9Cberschreitung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - monitorHeapAndReload() in /utils/common/monitorMemory.js ausgelagert - automatische Heap-Prüfung im 10s-Intervall in MapComponent integriert - reload bei Überschreitung von 8 GB Heap zur Stabilisierung bei Langzeitbetrieb - useEffect-Cleanup ergänzt mit clearInterval für sauberes Entfernen bei Unmount - Ziel: frühzeitige Entlastung vor möglichem Memory Overflow --- components/mainComponent/MapComponent.js | 9 ++++++++- config/appVersion.js | 2 +- utils/common/monitorMemory.js | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 utils/common/monitorMemory.js diff --git a/components/mainComponent/MapComponent.js b/components/mainComponent/MapComponent.js index 3b518cf36..9b786e53b 100644 --- a/components/mainComponent/MapComponent.js +++ b/components/mainComponent/MapComponent.js @@ -79,6 +79,7 @@ import useDynamicDeviceLayers from "@/hooks/useDynamicDeviceLayers.js"; import useDataUpdater from "@/hooks/useDataUpdater"; import { cleanupPolylinesForMemory } from "@/utils/polylines/cleanupPolylinesForMemory"; import { cleanupMarkers } from "@/utils/common/cleanupMarkers"; +import { monitorHeapAndReload } from "@/utils/common/monitorMemory"; //----------------------------------------------------------------------------------------------------- const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { //------------------------------- @@ -304,7 +305,6 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { // vorherige Marker & Polylinien vollständig bereinigen markers.forEach(marker => { - console.log("Marker-Typ:", marker.options); marker.remove(); }); cleanupPolylinesForMemory(polylines, map); @@ -780,6 +780,13 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { cleanupMarkers(markers, oms); }; }, []); + //-------------------------------------------- + // Überwacht den Speicherverbrauch und lädt die Seite neu, wenn er zu hoch ist, 8GB ist das Limit dann lädt die Seite neu + useEffect(() => { + const interval = monitorHeapAndReload(8, 10000); + + return () => clearInterval(interval); // wichtig: aufräumen! + }, []); //--------------------------------------------- //-------------------------------------------- return ( diff --git a/config/appVersion.js b/config/appVersion.js index 4af39151f..4489961ff 100644 --- a/config/appVersion.js +++ b/config/appVersion.js @@ -1,2 +1,2 @@ // /config/appVersion -export const APP_VERSION = "1.1.237"; +export const APP_VERSION = "1.1.238"; diff --git a/utils/common/monitorMemory.js b/utils/common/monitorMemory.js new file mode 100644 index 000000000..4354fdf5c --- /dev/null +++ b/utils/common/monitorMemory.js @@ -0,0 +1,14 @@ +export const monitorHeapAndReload = (limitInGB = 8, intervalMs = 10000) => { + const limit = limitInGB * 1024 * 1024 * 1024; + + return setInterval(() => { + const heap = performance.memory?.usedJSHeapSize || 0; + + console.log("Heap:", (heap / 1024 / 1024).toFixed(2), "MB"); + + if (heap > limit) { + console.warn("🚨 Heap-Limit erreicht. Reload wird ausgeführt."); + location.reload(); + } + }, intervalMs); +};