An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Memory Leak Guide

[![Documentation](https://img.shields.io/badge/docs-live-brightgreen)](https://memory-leak.khuong.dev/)
[![Language](https://img.shields.io/badge/languages-JS%20%7C%20TS%20%7C%20Java%20%7C%20Go%20%7C%20Kotlin-blue)]()
[![License](https://img.shields.io/badge/license-MIT-green)](./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 languages

Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.

## πŸ“„ License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.