How ananya-vastare/memory-leak-detector works
Project Type and Purpose
• This is a cross‐language monitoring tool / open-source utility that detects memory leaks in Java applications and provides live visualization. It consists of a Java component that samples and analyzes JVM memory usage, a log file for data exchange, and a Python script that renders live graphs.
File Structure Analysis
• All artifacts are at the project root:
• Main.java – entry point; Swing GUI + scheduling
• Memorychecker.java – gathers memory stats + leak detection logic
• MemoryAnanlyzer.java – low-level snapshot provider
• memory_plot.py – reads log and plots with matplotlib
• memory.log – append-only data exchange file
• No subfolders—modules are differentiated by filename and language.
Key Insights from README
• Java side uses ScheduledExecutorService to periodically sample memory and detect leak patterns.
• Swing GUI displays textual logs in real time.
• Python script tails memory.log and uses matplotlib for live plotting.
Diagramming the Architecture
a. Main Components
• JVM Application (MemorySampler)
– Subcomponents: MemoryAnalyzer, MemoryChecker
– Scheduler (ScheduledExecutorService)
– Swing GUI
• Data Exchange Layer
– memory.log file (append-only)
• Visualization Component
– Python Plotter (memory_plot.py)
– Matplotlib plotting engine
b. Relationships & Data Flow
1. Scheduler triggers MemoryAnalyzer → MemoryChecker
2. MemoryChecker writes timestamped metrics to memory.log
3. Swing GUI reads latest entries from memory.log (or directly from checker)
4. Python script tails memory.log and feeds data into matplotlib
c. Architectural Patterns & Principles
– Polling via ScheduledExecutorService (periodic sampling)
– Decoupling via file-based logs (loose coupling between Java and Python)
– MVC-style separation in Java: sampling logic (model), GUI (view)
– Single responsibility: Analyzer vs Checker vs Logger vs Plotter
d. Technologies & Frameworks
– Java 8+ (core language, concurrency APIs)
– Swing (UI)
– Python 3.x + matplotlib
– Standard I/O and file APIs for cross-language integration
Essential Elements Checklist
• [ ] Sufficient whitespace so connectors do not overlap text
• [ ] Annotation of key technologies next to each component