diff --git a/96-Memory Leak Detection/index.html b/96-Memory Leak Detection/index.html new file mode 100644 index 0000000..cb80566 --- /dev/null +++ b/96-Memory Leak Detection/index.html @@ -0,0 +1,21 @@ + + + + + + + Memory Leak Detection App + + +
+

Memory Leak Detection App

+ + +
+ Memory Usage: 0 MB +
+
+ + + + diff --git a/96-Memory Leak Detection/script.js b/96-Memory Leak Detection/script.js new file mode 100644 index 0000000..839f745 --- /dev/null +++ b/96-Memory Leak Detection/script.js @@ -0,0 +1,29 @@ +let memoryLeakArray = []; +let memoryLeakInterval; +let memoryUsageElement = document.getElementById("usageValue"); + +function startMemoryLeak() { + memoryLeakInterval = setInterval(() => { + const newData = new Array(100000).fill("MemoryLeakData"); + memoryLeakArray = memoryLeakArray.concat(newData); + updateMemoryUsage(); + console.log("Memory Leak Detected!"); + }, 1000); +} + +function stopMemoryLeak() { + clearInterval(memoryLeakInterval); +} + +function updateMemoryUsage() { + const usedMemory = ( + performance.memory.usedJSHeapSize / + (1024 * 1024) + ).toFixed(2); + memoryUsageElement.textContent = `${usedMemory} MB`; +} + +document + .getElementById("startButton") + .addEventListener("click", startMemoryLeak); +document.getElementById("stopButton").addEventListener("click", stopMemoryLeak); diff --git a/96-Memory Leak Detection/styles.css b/96-Memory Leak Detection/styles.css new file mode 100644 index 0000000..2419b94 --- /dev/null +++ b/96-Memory Leak Detection/styles.css @@ -0,0 +1,23 @@ +body { + font-family: Arial, sans-serif; + display: flex; + align-items: center; + justify-content: center; + height: 100vh; + margin: 0; +} + +.container { + text-align: center; +} + +button { + padding: 10px 20px; + font-size: 16px; + margin: 10px; +} + +#memoryUsage { + margin-top: 20px; + font-size: 18px; +}