
# Nicelight Memory Fix Deep (Forge 1.20.1)
**Nicelight Memory Fix Deep** is a memory-leak mitigation and cache-management utility for Minecraft Forge 1.20.1, **specifically tailored for heavy modpacks and marathon gaming sessions**.
In large modpacks with extensive exploration, combat, and dimension-hopping, memory leaks gradually accumulate over time. This mod keeps your game running smoothly over hours of continuous play by actively severing orphaned references that Java's Garbage Collector cannot clean up on its own.
📌 What This Mod Does:
🤝 Compatibility with Other Optimization Mods
Designed to run smoothly alongside the modern optimization stack with zero mixin conflicts:
1. **Vanilla Bug Fixes**:
* **MC-101260 Fix**: Clears player raycast crosshair pointers on world unload so old worlds can be garbage collected.
* **MC-260605 Fix**: Cleans dead mob `Brain` memory references upon entity removal.
* **LevelRenderer Patch**: Flushes the `destroyingBlocks` map when leaving a dimension to prevent texture leak.
* **SoundEngine Patch**: Drains the `instanceToChannel` map on sound stop to stop OpenAL audio handle leaks.
* **MapRenderer Patch**: Evicts stale held-map textures from memory when closed.
* **Biome Temperature Cache**: Purges `ThreadLocal` temperature caches during cleanup.
2. **ThreadLocal Leak Mitigation**:
* Scans background worker threads (Forge/Netty/Minecraft) using an internal JVM `Unsafe` bypass to detach retained world/class objects without requiring `--add-opens` flags.
3. **Safe Brain AI Cleanup (100% Epic Fight Compatible)**:
* Sets expired mob memory targets to `Optional.empty()` instead of deleting map keys. This severs memory links from dead mobs while preserving complete crash-free stability with **Epic Fight** and combat animation mods.
4. **World & Chunk Ticket Eviction**:
* Purges stale `DistanceManager` tickets, evicts unloaded POI `SectionStorage`, and flushes cached 3D `StructureTemplate` NBT data.
5. **Audio & VRAM Maintenance**:
* Stops looping ghost sound channels and reclaims orphaned OpenAL audio buffers back to the operating system.
* Trims `BufferBuilder` native memory allocations.
6. **Non-Intrusive Heap Pressure Automation**:
* Monitors RAM at 50% (Soft), 70% (Light), and 82% (Strong).
* Sweeps run silently in milliseconds without calling forced `System.gc()` freezes during play.
---
### ⌨️ All In Commands (`/nm` or `/nmem`)
* `/nm stats` (or `/nm`) — Displays real-time used RAM, committed memory, watchdog world status, and active mixin interception counters.
* `/nm sweep` — **[Full Deep Clean]** Manually triggers a comprehensive purge across all 16+ cache tiers (audio, textures, chunk tickets, threadlocals, brain memories) and prints a breakdown report in chat.
* `/nm scan` — Runs a read-only diagnostic scan to detect suspect objects currently retained on background worker threads.
* `/nm gc` — Executes targeted cache cleanups and manually triggers a single JVM Garbage Collection cycle.
* `/nm pressure` — Evaluates current heap pressure against configured thresholds and runs the corresponding cleanup tier.
* `/nm watchdog` — Checks whether any unloaded dimensions or worlds are still alive in memory.
* `/nm config` — Prints a summary of all active configuration settings.
* `/nm discover` — Manually scans loaded mod jars to discover newly loaded cache classes.
---
### ⚙️ Configuration
All settings can be customized in: `config/nicelight_memoryfix_deep.json`

