A lightweight Windows RAM optimizer written in C++ that uses native NT APIs to clean memory without relying on third-party tools like RAMMap or EmptyStandbyList.exe.
Designed for systems with persistent Nonpaged Pool bloat caused by drivers or security software (antivirus, VPN agents, RGB controllers), this tool reclaims memory at the kernel level on a configurable schedule.
- No external dependencies — uses
NtSetSystemInformationdirectly fromntdll.dll - Full memory pipeline cleanup: Working Sets → Modified Page List → Low Priority Standby → Standby List
- Smart threshold system — aggressive kernel trim only triggers when Nonpaged Pool exceeds a configurable threshold (default: 800 MB), avoiding unnecessary page faults
- Real-time Nonpaged Pool monitoring via
GetPerformanceInfo(psapi) — reliable across all Windows 10/11 builds - Detailed logging with timestamps to
C:\Scripts\limpieza_ram.log - Privilege auto-elevation — automatically acquires
SeProfileSingleProcess,SeIncBasePriority, andSeDebugprivileges - Configurable interval — run every N minutes via
-iflag - Silent mode — runs completely in the background via
-sflag - Windows Task Scheduler integration — launches at logon with highest privileges
- Windows 10 or Windows 11 (x64)
- Must be run as Administrator
- For full kernel-level trim (
SeLockMemoryPrivilege): assign the privilege via Local Group Policy (see Advanced Setup)
- Visual Studio 2019/2022 with Desktop development with C++ workload, or
- MinGW-w64 / w64devkit
- Open Visual Studio → Create new project → Empty Project (C++)
- Add
RAMOptimizerV2.cppto the project (right-click Source Files → Add → Existing Item) - The
#pragma comment(lib, ...)directives handle linking automatically - Build with
Ctrl+Shift+B
Or from Developer Command Prompt for VS:
cl /O2 /EHsc RAMOptimizerV2.cpp /link advapi32.lib psapi.libg++ -O2 -std=c++17 -o RAMOptimizerV2.exe RAMOptimizerV2.cpp -ladvapi32 -lpsapi -static- Copy
RAMOptimizerV2.exetoC:\Scripts\ - Register as a scheduled task (runs at logon, highest privileges):
$action = New-ScheduledTaskAction -Execute "C:\Scripts\RAMOptimizerV2.exe" -Argument "-s -i 120"
$trigger = New-ScheduledTaskTrigger -AtLogOn
$principal = New-ScheduledTaskPrincipal -UserId "$env:USERNAME" -RunLevel Highest
Register-ScheduledTask -TaskName "RAMOptimizerV2" -Action $action -Trigger $trigger -Principal $principal -Force- Start it immediately without rebooting:
Start-Process "C:\Scripts\RAMOptimizerV2.exe" -ArgumentList "-s -i 120" -Verb RunAsRAMOptimizerV2.exe [options]
Options:
-s, --silent Silent mode (no console output, background only)
-i, --interval <min> Cleanup interval in minutes (default: 120)
-once Run a single cleanup cycle and exit
-l, --log <path> Custom log file path (default: C:\Scripts\limpieza_ram.log)
# Run once and show output (useful for testing)
RAMOptimizerV2.exe -once
# Silent background mode, every 2 hours
RAMOptimizerV2.exe -s -i 120
# Silent background mode, every hour
RAMOptimizerV2.exe -s -i 60
# Custom log path
RAMOptimizerV2.exe -s -i 120 -l "D:\Logs\ram.log"RAMOptimizer v2.2
Privileges: SeProfileSingleProcess=OK SeIncBasePriority=OK SeDebug=OK
Interval: 120 min | NonPaged threshold: 800 MB
Log: C:\Scripts\limpieza_ram.log
[2026-03-27 11:47:26] RAMOptimizer v2.2 started | interval: 120 min | silent=no | once=yes
[2026-03-27 11:47:26] === Starting RAM cleanup ===
[2026-03-27 11:47:26] NonPaged Pool before: 891 MB
[2026-03-27 11:47:26] Working sets trimmed: 240 processes | freed: 10645 MB
[2026-03-27 11:47:27] System WS trim (kernel/drivers): OK
[2026-03-27 11:47:27] Modified Page List: OK
[2026-03-27 11:47:28] Low Priority Standby: OK
[2026-03-27 11:47:29] Standby List: OK
[2026-03-27 11:47:29] NonPaged Pool after: 743 MB
[2026-03-27 11:47:29] NonPaged Pool reduction: -148 MB
[2026-03-27 11:47:29] === Cleanup completed ===
Windows allocates RAM in several layers. Over time, drivers and system services accumulate pages in the Nonpaged Pool (kernel memory that cannot be paged to disk) and Standby List (pages no longer actively used but kept cached). This tool cleans them in order:
1. Working Set Trim → moves idle process pages to Standby
2. System WS Trim → trims kernel/driver pages (requires SeLockMemoryPrivilege)
3. Modified Page List → flushes dirty pages to the paging file
4. Low Priority Standby → purges lowest-priority cached pages
5. Standby List → purges all remaining cached pages
The smart threshold prevents unnecessary cleaning: System WS Trim only runs when Nonpaged Pool exceeds 800 MB, avoiding performance degradation from excessive page faults when memory pressure is low.
By default, even Administrators cannot trim the kernel working set. To enable it:
- Open
gpedit.msc - Navigate to: Computer Configuration → Windows Settings → Security Settings → Local Policies → User Rights Assignment
- Double-click "Lock pages in memory"
- Click "Add User or Group" and add your username
- Restart the system
After reboot, System WS trim will show OK and Nonpaged Pool reduction will be significantly larger.
Low Priority Standbypurge may showFAILwhen the list is empty — this is normal behaviorSystem WS trimrequiresSeLockMemoryPrivilege(see Advanced Setup)- Running without Administrator privileges will result in reduced effectiveness
RAMMap is an excellent diagnostic tool but its command-line interface changed behavior in v1.61+, breaking automation scripts that relied on -Et flags. This tool replaces that dependency entirely by calling the same underlying NT APIs directly, with no external binaries required.
MIT License — free to use, modify, and distribute.
AcidClawX41 — github.com/AcidClawX41