Skip to content

Optimization of Temp Files Purge Protocol #1

@zyrou-afk

Description

@zyrou-afk
  • Analysis of Current State:The existing 10-second interval for clearing temporary directories is excessively aggressive. This frequency creates critical I/O conflicts and race conditions. Many active processes—specifically Python runtime environments and browser download managers—rely on the temp directory for atomic writes, data buffering, and lock files. Deleting these assets prematurely results in "Permission Denied" errors, corrupted downloads, and fatal application crashes.

    • Proposed Patch Logic :

    -1) To balance system operational stability, I suggest the following adjustments:

    1 - Initialization Trigger : Execute a comprehensive cache clear only once upon application startup to ensure a clean slate.
    2 - Throttled Recurrence : Increase the automated cleanup delay from 10 seconds to 5 minutes (300 seconds).

    -2) Key Benefits:

    1 - Process Integrity : Provides a sufficient "Time-to-Live" (TTL) for temporary assets, allowing scripts and downloads to complete without
    interference.
    2 - Reduced Overhead: Minimizes unnecessary CPU cycles and disk thrashing caused by constant directory polling.
    3 - System Stability: Eliminates the risk of blocking core programs that require persistent access to temporary workspace during execution.

    -3) The patch code of "clear_ram_loop.bat"

@echo off
title Windows Optimizer Script
color 0A

:: === One-time: Disable Windows Updates ===
echo [*] Disabling Windows Updates...
sc stop wuauserv >nul 2>&1
sc config wuauserv start= disabled >nul 2>&1
sc stop UsoSvc >nul 2>&1
sc config UsoSvc start= disabled >nul 2>&1
sc stop bits >nul 2>&1
sc config bits start= disabled >nul 2>&1

reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v NoAutoUpdate /t REG_DWORD /d 1 /f >nul
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" /v AUOptions /t REG_DWORD /d 1 /f >nul
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\PushNotifications" /v ToastEnabled /t REG_DWORD /d 0 /f >nul

schtasks /Change /TN "Microsoft\Windows\WindowsUpdate\Scheduled Start" /Disable >nul 2>&1
schtasks /Change /TN "Microsoft\Windows\WindowsUpdate\sih" /Disable >nul 2>&1
schtasks /Change /TN "Microsoft\Windows\WindowsUpdate\sihboot" /Disable >nul 2>&1

echo [✓] Windows Update Disabled.
echo.

:: === Clean temp folders ===
echo [*] Cleaning temp folders...
del /q /f /s %TEMP%* >nul 2>&1
del /q /f /s C:\Windows\Temp* >nul 2>&1

:loop
echo ============================
echo [*] Starting Optimization Loop
echo ============================

:: === Show RAM usage before ===
echo [*] RAM Usage Before:
powershell -command "Get-CimInstance Win32_OperatingSystem | ForEach-Object { Write-Output ('Used: {0:N2} GB / Total: {1:N2} GB' -f (($.TotalVisibleMemorySize - $.FreePhysicalMemory)/1MB), ($_.TotalVisibleMemorySize/1MB)) }"

:: === Flush DNS ===
echo [*] Flushing DNS cache...
ipconfig /flushdns >nul

:: === Clear RAM ===
echo [*] Attempting RAM Trim...
powershell -command "Get-Process | Where-Object { $.Id -ne $PID } | ForEach-Object { try { $.MinWorkingSet = $_.MinWorkingSet } catch {} }"

:: === Show RAM usage after ===
echo [*] RAM Usage After:
powershell -command "Get-CimInstance Win32_OperatingSystem | ForEach-Object { Write-Output ('Used: {0:N2} GB / Total: {1:N2} GB' -f (($.TotalVisibleMemorySize - $.FreePhysicalMemory)/1MB), ($_.TotalVisibleMemorySize/1MB)) }"

:: === Close bloat background tasks ===
echo [*] Killing background apps...
taskkill /f /im OneDrive.exe >nul 2>&1
taskkill /f /im Teams.exe >nul 2>&1
taskkill /f /im AdobeIPCBroker.exe >nul 2>&1
taskkill /f /im AdobeCollabSync.exe >nul 2>&1
taskkill /f /im ArmouryCrate.UserSessionHelper.exe
taskkill /f /im GameSDK.exe
taskkill /f /im NahimicService.exe
taskkill /f /im AuraService.exe

:: === Run RamMap to clear standby list ===
echo [*] Running RamMap64 to clear standby memory...

:: Accept the EULA silently to prevent dialog
reg add "HKCU\Software\Sysinternals\RamMap" /v EulaAccepted /t REG_DWORD /d 1 /f >nul

:: Run RamMap silently with the -Et -Es -Em -Ew flag to clear everything
"D:\WindBatchCustom\RAMMap64.exe" -Et -Es -Em -Ew

echo [✓] Cleanup Done. Sleeping for 5 minutes...
timeout /t 300 >nul
goto loop

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions