Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RAMOptimizer-Windows

Platform Language License Version

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.


Features

  • No external dependencies — uses NtSetSystemInformation directly from ntdll.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, and SeDebug privileges
  • Configurable interval — run every N minutes via -i flag
  • Silent mode — runs completely in the background via -s flag
  • Windows Task Scheduler integration — launches at logon with highest privileges

Requirements

  • 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)

Build requirements

  • Visual Studio 2019/2022 with Desktop development with C++ workload, or
  • MinGW-w64 / w64devkit

Building

Visual Studio (MSVC)

  1. Open Visual Studio → Create new project → Empty Project (C++)
  2. Add RAMOptimizerV2.cpp to the project (right-click Source Files → Add → Existing Item)
  3. The #pragma comment(lib, ...) directives handle linking automatically
  4. Build with Ctrl+Shift+B

Or from Developer Command Prompt for VS:

cl /O2 /EHsc RAMOptimizerV2.cpp /link advapi32.lib psapi.lib

MinGW / w64devkit

g++ -O2 -std=c++17 -o RAMOptimizerV2.exe RAMOptimizerV2.cpp -ladvapi32 -lpsapi -static

Installation

  1. Copy RAMOptimizerV2.exe to C:\Scripts\
  2. 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
  1. Start it immediately without rebooting:
Start-Process "C:\Scripts\RAMOptimizerV2.exe" -ArgumentList "-s -i 120" -Verb RunAs

Usage

RAMOptimizerV2.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)

Examples

# 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"

Sample Output

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 ===

How It Works

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.


Advanced Setup

Enable full kernel-level trim (SeLockMemoryPrivilege)

By default, even Administrators cannot trim the kernel working set. To enable it:

  1. Open gpedit.msc
  2. Navigate to: Computer Configuration → Windows Settings → Security Settings → Local Policies → User Rights Assignment
  3. Double-click "Lock pages in memory"
  4. Click "Add User or Group" and add your username
  5. Restart the system

After reboot, System WS trim will show OK and Nonpaged Pool reduction will be significantly larger.


Known Limitations

  • Low Priority Standby purge may show FAIL when the list is empty — this is normal behavior
  • System WS trim requires SeLockMemoryPrivilege (see Advanced Setup)
  • Running without Administrator privileges will result in reduced effectiveness

Why Not Use RAMMap?

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.


License

MIT License — free to use, modify, and distribute.


Author

AcidClawX41 — github.com/AcidClawX41

About

Native Windows RAM optimizer using NT APIs — no external dependencies required

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages