## Memory Issue Detection

> Memory issues are categorized into three types based on language memory management models: manual management (C/C++/Rust), GC (Java/JS/Python/Go), and cross-language general.
> This file is the detection routing table -- it locates the detection subtask subfiles to load based on code characteristics and language type.

### Detection Routing Table

| Trigger Signals (Code Characteristics) | Language Scope | Detection Subtask Triggered | File |
|---------------------|---------|-----------|------|
| Array/pointer index access (`arr[i]`, `*(ptr + i)`) without bounds checking | C/C++/Rust | Buffer Overflow | [buffer-overflow.md](buffer-overflow.md) |
| Unsafe functions (`strcpy`/`sprintf`/`gets`/`memcpy` without length parameter) | C/C++ | Buffer Overflow | [buffer-overflow.md](buffer-overflow.md) |
| Slice/pointer operations in Rust `unsafe` blocks | Rust | Buffer Overflow | [buffer-overflow.md](buffer-overflow.md) |
| Continued use of pointer/reference after `free`/`delete`/`drop` | C/C++/Rust | Use After Free | [use-after-free.md](use-after-free.md) |
| Function returning pointer/reference to local variable (`return &local`) | C/C++ | Use After Free | [use-after-free.md](use-after-free.md) |
| Iterator invalidation (deleting/modifying container elements in a loop) | C++/Rust | Use After Free | [use-after-free.md](use-after-free.md) |
| Same pointer `free`/`delete`/`drop` multiple times | C/C++/Rust | Memory Allocation Defects | [memory-allocation.md](memory-allocation.md) |
| `malloc`/`new` without corresponding `free`/`delete` (on all paths) | C/C++/Rust | Memory Allocation Defects | [memory-allocation.md](memory-allocation.md) |
| `malloc`/`free` mixed with `new`/`delete` | C/C++ | Memory Allocation Defects | [memory-allocation.md](memory-allocation.md) |
| Use of uninitialized local variables/memory | C/C++ | Unsafe Operations | [unsafe-operations.md](unsafe-operations.md) |
| Raw pointer dereference in Rust `unsafe` blocks (`*raw_ptr`) | Rust | Unsafe Operations | [unsafe-operations.md](unsafe-operations.md) |
| Allocation size calculated from external input without overflow validation | C/C++/Rust | Unsafe Operations | [unsafe-operations.md](unsafe-operations.md) |
| Objects holding mutual references (A→B→A), especially via callbacks/closures | GC Languages | Reference Retention | [reference-retention.md](reference-retention.md) |
| Closures capturing external variables but closure lifetime exceeds expectation | GC Languages | Reference Retention | [reference-retention.md](reference-retention.md) |
| Global cache Map/Set/Dict only has `put`/`add` without `remove`/`evict` | GC Languages | Unbounded Collection Growth | [collection-growth.md](collection-growth.md) |
| `addEventListener`/`on`/`subscribe` without paired `removeEventListener`/`off`/`unsubscribe` | GC Languages | Callback Leak | [callback-leak.md](callback-leak.md) |
| `setInterval`/`setTimeout` without paired `clearInterval`/`clearTimeout` | GC Languages | Callback Leak | [callback-leak.md](callback-leak.md) |
| File/network/database connections (`open`/`connect`/`createConnection`) | All Languages | Resource Leak | [resource-leak.md](resource-leak.md) |
| Resources created in try-catch without finally/using/defer release | All Languages | Resource Leak | [resource-leak.md](resource-leak.md) |
| Unstopped goroutines/threads (function exits but thread still running) | Go/Java | Resource Leak | [resource-leak.md](resource-leak.md) |

### Usage

1. Identify the programming language and memory management model of the changed code
2. Read the changed code and match the trigger signals above
3. Based on matched trigger signals, **only load** the corresponding subfiles (no need to load everything)
4. No matched trigger signals → do not execute memory issue detection
5. When the same trigger signal corresponds to multiple detection subtasks, execute by priority: manual management language issues > cross-language resource leaks > GC language issues

### General Exclusion Rules

The following situations are not reported as defects:
- **Test files**: `*.test.*`, `*.spec.*`, `__tests__/` directories
- **Generated code**: `generated/`, `*.generated.*`, `node_modules/`, vendor
- **Third-party dependencies**: uncontrollable external library code
- **Clear TODO/FIXME comments**: issues already known to the developer
- **Within language safety guarantees**: Rust safe code memory safety, Go bounds checking (guaranteed by compiler/runtime)
