File tree Expand file tree Collapse file tree 3 files changed +73
-0
lines changed Expand file tree Collapse file tree 3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < link rel ="stylesheet " href ="styles.css " />
7+ < title > Memory Leak Detection App</ title >
8+ </ head >
9+ < body >
10+ < div class ="container ">
11+ < h1 > Memory Leak Detection App</ h1 >
12+ < button id ="startButton "> Start Memory Leak</ button >
13+ < button id ="stopButton "> Stop Memory Leak</ button >
14+ < div id ="memoryUsage ">
15+ Memory Usage: < span id ="usageValue "> 0</ span > MB
16+ </ div >
17+ </ div >
18+
19+ < script src ="script.js "> </ script >
20+ </ body >
21+ </ html >
Original file line number Diff line number Diff line change 1+ let memoryLeakArray = [ ] ;
2+ let memoryLeakInterval ;
3+ let memoryUsageElement = document . getElementById ( "usageValue" ) ;
4+
5+ function startMemoryLeak ( ) {
6+ memoryLeakInterval = setInterval ( ( ) => {
7+ const newData = new Array ( 100000 ) . fill ( "MemoryLeakData" ) ;
8+ memoryLeakArray = memoryLeakArray . concat ( newData ) ;
9+ updateMemoryUsage ( ) ;
10+ console . log ( "Memory Leak Detected!" ) ;
11+ } , 1000 ) ;
12+ }
13+
14+ function stopMemoryLeak ( ) {
15+ clearInterval ( memoryLeakInterval ) ;
16+ }
17+
18+ function updateMemoryUsage ( ) {
19+ const usedMemory = (
20+ performance . memory . usedJSHeapSize /
21+ ( 1024 * 1024 )
22+ ) . toFixed ( 2 ) ;
23+ memoryUsageElement . textContent = `${ usedMemory } MB` ;
24+ }
25+
26+ document
27+ . getElementById ( "startButton" )
28+ . addEventListener ( "click" , startMemoryLeak ) ;
29+ document . getElementById ( "stopButton" ) . addEventListener ( "click" , stopMemoryLeak ) ;
Original file line number Diff line number Diff line change 1+ body {
2+ font-family : Arial, sans-serif;
3+ display : flex;
4+ align-items : center;
5+ justify-content : center;
6+ height : 100vh ;
7+ margin : 0 ;
8+ }
9+
10+ .container {
11+ text-align : center;
12+ }
13+
14+ button {
15+ padding : 10px 20px ;
16+ font-size : 16px ;
17+ margin : 10px ;
18+ }
19+
20+ # memoryUsage {
21+ margin-top : 20px ;
22+ font-size : 18px ;
23+ }
You can’t perform that action at this time.
0 commit comments