https://github.com/lamngockhuong/memory-leak
Memory leak demo & solutions
https://github.com/lamngockhuong/memory-leak
demo-app memory-leak nestjs nodejs
Last synced: about 2 months ago
JSON representation
Memory leak demo & solutions
- Host: GitHub
- URL: https://github.com/lamngockhuong/memory-leak
- Owner: lamngockhuong
- License: mit
- Created: 2025-05-18T22:31:12.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-08-26T23:49:59.000Z (about 2 months ago)
- Last Synced: 2025-08-27T08:23:39.150Z (about 2 months ago)
- Topics: demo-app, memory-leak, nestjs, nodejs
- Language: TypeScript
- Homepage: http://memory-leak.khuong.dev/
- Size: 229 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Memory Leak Guide
[](https://memory-leak.khuong.dev/)
[]()
[](./LICENSE)A comprehensive guide and demo project to understand, detect, and prevent memory leaks across multiple programming languages.
## π― Overview
This project provides:
- **π Comprehensive documentation** on memory leak patterns and prevention
- **π οΈ Hands-on demo applications** in JavaScript/TypeScript, Java, Kotlin, and Go
- **π§ Real-world tools and utilities** for memory leak detection
- **π Best practices** for production monitoring and prevention## π Documentation
Visit our comprehensive guide: **[https://memory-leak.khuong.dev/](https://memory-leak.khuong.dev/)**
Available in:
- πΊπΈ [English](https://memory-leak.khuong.dev/)
- π»π³ [TiαΊΏng Viα»t](https://memory-leak.khuong.dev/vi/)## π Quick Start
### JavaScript/TypeScript (Node.js)
```bash
cd nodejs/nestjs-demo
pnpm install
HEAPDUMP_ENABLED=1 pnpm run start:dev# Trigger a memory leak
curl -X POST http://localhost:3000/global-variable-leak
```### Java (Coming Soon)
```bash
cd java/demo
./gradlew run
```### Go (Coming Soon)
```bash
cd go/demo
go run main.go
```### Kotlin (Coming Soon)
```bash
cd kotlin/demo
./gradlew run
```## π Project Structure
```
memory-leak/
βββ docs/ # Documentation website (VitePress)
β βββ .vitepress/ # VitePress configuration
β βββ introduction/ # Basic concepts
β βββ patterns/ # Common leak patterns
β βββ languages/ # Language-specific guides
β βββ tools/ # Detection and analysis tools
β βββ demos/ # Demo project documentation
β βββ vi/ # Vietnamese documentation
βββ nodejs/ # Node.js/TypeScript demos
β βββ nestjs-demo/ # NestJS application with leak examples
β βββ src/utils/ # Memory leak utilities
β β βββ leak-global.ts # Global variable leaks
β β βββ leak-closure.ts # Closure leaks
β β βββ leak-event.ts # Event listener leaks
β β βββ leak-timer.ts # Timer leaks
β β βββ leak-cache.ts # Cache leaks
β β βββ heapdump.ts # Heap dump utilities
β βββ test/bruno/ # API test collections
βββ java/ # Java demo applications (planned)
βββ kotlin/ # Kotlin demo applications (planned)
βββ go/ # Go demo applications (planned)
βββ README.md
```## π‘ What You'll Learn
### Memory Leak Patterns
- **Global Variables** - Variables that accumulate data without bounds
- **Event Listeners** - Unremoved listeners preventing garbage collection
- **Closures** - Functions capturing large contexts unintentionally
- **Timers & Intervals** - Periodic tasks that never clean up
- **Caching** - Caches that grow without limits
- **DOM References** - Detached DOM nodes still referenced in JavaScript### Detection Techniques
- **Heap Dump Analysis** - Taking and analyzing memory snapshots
- **Profiling Tools** - Using browser DevTools and Node.js profilers
- **Memory Monitoring** - Setting up production monitoring
- **Automated Testing** - Writing tests to catch memory leaks### Language-Specific Guides
- **JavaScript/TypeScript** - Browser and Node.js environments
- **Java** - JVM memory management and tools
- **Kotlin** - Both JVM and Native considerations
- **Go** - Goroutines and garbage collection## π€ Contributing
We welcome contributions! Whether it's:
- π Improving documentation
- π Fixing bugs in demo applications
- π‘ Adding new memory leak patterns
- π Translating content
- π οΈ Adding support for new languagesPlease see our [Contributing Guidelines](CONTRIBUTING.md) for details.
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.