How to Fix: Chrome Slow: CPU, Mem High? Daily Reset Script

Dennis Faas's picture

Infopackets Readers Jay S. writes:

" Dear Dennis,

Thanks for your article on How to Fix: Brave Browser Slow (High CPU, RAM) Script. I have a similar question, but this time it's with Chrome. As with the other user mentioned in your article, every so often Chrome starts to lag and become unresponsive / slow. When I check Task Manager, I often see some of the chrome.exe processes eating up 2GB+ of memory. I'm not using any extensions, so I'm not sure why this happens, other than perhaps Chrome is caching too much information or there is a memory leak of some kind.

Anyhow, I would like to have an automated script that will close Chrome.exe at 6am and relaunch it so that it's fast and fresh to use in the morning. I will pay you to remote into my machine and come up with a solution. I do have some stipulations: I am running a multi-user environment with RDP Wrapper and have multiple users on my machine and they all use their own chrome.exe executables. I tried your script from the Chrome article you wrote but it won't close Chrome, so I think the script needs some tweaking. "

My response:

I asked Jay if he would like me to connect to his machine to look into the issue with my remote desktop service, and he agreed.

Below I will discuss my findings.

How to Fix: Chrome Slow: CPU, Mem High? Daily Reset Script

After some extended experimenting, I put together a working batch script to resolve Chrome's high CPU usage and excessive memory drain. The script is designed to safely shut down Chrome in a multi-user (or single user) environment, ensure it's fully closed, then restarts Chrome automatically daily at 6am (or whenever the user wants to run the script).

The script can be run using Task Manager on demand (at 6am daily, for example). This helps keep Chrome running fast and lag-free without performance hiccups and without losing your open tabs. The script keeps a log file to tell you when it ran and then truncates the log. It will only run under the current user so it is safe to run in a multi-user (or single user) environment.

How The Chrome Daily Reset Script Works

When the script runs, it sends a graceful exit request to Chrome. The script then monitors Chrome's processes to ensure they've fully cleared from memory. Once Chrome is confirmed closed, the script pauses for a few seconds and then starts it up again - ready to pick up where you left off without the bloat.

Before You Use the Script

  1. Enable Tab Session Restore in Chrome: You need to make sure Chrome resumes where it left off after a restart.
     
    • Launch chrome and paste in the following into Chrome's URL path

      chrome://settings/onStartup
       
    • Select "Continue where you left off"
       
  2. Make Chrome the Default Browser: In order for the script to be able to open web links in third party programs (like email), it needs to be set as default browser.
     
    • Launch chrome and paste in the following into Chrome's URL path:

      chrome://settings/defaultBrowser
       
    • Click "Make Chrome your default browser"

Here is the Script

  1. Highlight the text block below with your mouse. Right-click the highlighted area and choose Copy to place the script in your clipboard.

    @echo off
    setlocal enabledelayedexpansion

    rem "C:\Program Files (x86)\Google\Chrome\Application\chrome_restart.bat"
    rem "C:\Program Files\Google\Chrome\Application\chrome_restart.bat"
    rem chrome://settings/onStartup -> continue where you left off
    rem chrome://settings/defaultBrowser -> set chrome as default

    REM --- Detect Chrome Path ---
    if exist "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" (
    set "CHROME_PATH=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
    ) else if exist "C:\Program Files\Google\Chrome\Application\chrome.exe" (
    set "CHROME_PATH=C:\Program Files\Google\Chrome\Application\chrome.exe"
    ) else (
    echo Chrome not found in either location. Exiting.
    exit /b
    )

    REM --- CONFIGURATION ---
    set "USERNAME=%USERNAME%"
    set "MAX_RETRIES=15"
    set "LOG_FILE=%~dp0chrome_restart.log"

    REM --- SETTINGS REMINDER ---
    REM chrome://settings/onStartup -> Select: 'Continue where you left off"
    REM chrome://flags -> Search: "Enable crash recovery bubbles" -> Set to: Disabled

    echo [%DATE% %TIME%] --- Script started --- >> "%LOG_FILE%"

    REM --- Get main chrome.exe PID for current user (excluding subprocesses) ---
    for /f %%A in ('powershell -NoProfile -Command "Get-WmiObject Win32_Process | Where-Object { $_.Name -eq 'chrome.exe' -and $_.CommandLine -notmatch '--type=' -and $_.GetOwner().User -eq '%USERNAME%' } | Select-Object -First 1 -ExpandProperty ProcessId"') do set "MAINPID=%%A"

    if "%MAINPID%"=="" (
    echo [%DATE% %TIME%] No main chrome process found for user %USERNAME%. Exiting. >> "%LOG_FILE%"
    goto TRIMLOG
    )

    echo [%DATE% %TIME%] Main chrome process is PID %MAINPID%. Closing... >> "%LOG_FILE%"
    powershell -NoProfile -Command "Get-Process -Id %MAINPID% | ForEach-Object { $_.CloseMainWindow() | Out-Null }"

    REM --- Wait until the main window is gone (not just the PID)
    echo [%DATE% %TIME%] Waiting for chrome main window to close (gracefully only)... >> "%LOG_FILE%"
    set RETRIES=0
    :WAITLOOP
    timeout /t 2 >nul
    set /a RETRIES+=1

    powershell -NoProfile -Command "$proc = Get-Process -Id %MAINPID% -ErrorAction SilentlyContinue; if ($proc -and $proc.MainWindowHandle -ne 0) { exit 1 } else { exit 0 }"
    if %errorlevel%==0 (
    echo [%DATE% %TIME%] chrome window has closed. Waiting 3 seconds before relaunch... >> "%LOG_FILE%"
    timeout /t 3 >nul
    goto LAUNCH
    )

    if !RETRIES! GEQ %MAX_RETRIES% (
    echo [%DATE% %TIME%] chrome window did not close after %MAX_RETRIES% attempts. Skipping restart. >> "%LOG_FILE%"
    goto TRIMLOG
    )
    goto WAITLOOP

    :LAUNCH
    echo [%DATE% %TIME%] Relaunching chrome... >> "%LOG_FILE%"
    rem testing / won't open http links in email: start "" "%CHROME_PATH%"
    rem below fixes that but you need to register chrome as default browser via chrome://settings/defaultBrowser
    start "" "explorer.exe" "https://"

    REM --- OPTIONAL: Clean up orphan chrome child processes tied to previous session ---
    REM --- Uncomment below if you want to force-remove orphaned subprocesses from the old main PID ---
    REM timeout /t 5 >nul
    REM echo Cleaning up orphan chrome child processes from PID %MAINPID%... >> "%LOG_FILE%"
    REM powershell -NoProfile -Command "Get-WmiObject Win32_Process ^| Where-Object { $_.Name -eq 'chrome.exe' -and $_.ParentProcessId -eq %MAINPID% -and $_.GetOwner().User -eq '%USERNAME%' } ^| ForEach-Object { Stop-Process -Id $_.ProcessId -Force }"

    :TRIMLOG
    REM --- TRIM LOG FILE TO LAST 100 LINES ---
    set "LOG_TEMP=%TEMP%\chrome_log_trim.tmp"
    powershell -NoProfile -Command "Get-Content -Path '%LOG_FILE%' -Tail 100 | Set-Content -Path '%LOG_TEMP%'"
    copy /y "%LOG_TEMP%" "%LOG_FILE%" >nul
    del "%LOG_TEMP%" >nul 2>&1

    :DONE
    echo [%DATE% %TIME%] Done. >> "%LOG_FILE%"
    endlocal
    exit /b
     
  2. Paste the script into Notepad. Click Start, type notepad, then right-click Notepad and select Run as Administrator.
     
  3. In Notepad, click Edit -> Paste. The script should now appear in Notepad.
     
  4. Check to see where you have Chrome installed. It should either be:

    "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" OR
    "C:\Program Files\Google\Chrome\Application\chrome.exe"

     
  5. Next, save the file by clicking File -> Save As, then type the filename with quotes exactly as shown below (depending on your install location):

    "C:\Program Files (x86)\Google\Chrome\Application\chrome_restart.bat" OR
    "C:\Program Files\Google\Chrome\Application\chrome_restart.bat"

Running the Script Manually

  1. Open Chrome manually so it's running and open a few tabs with different URLs to make sure Chrome is remembering what you had opened previously.
     
  2. Now it's time to test the script. Click Start, type cmd.exe, then right-click Command Prompt and select Run as Administrator.
     
  3. Highlight and copy one of the lines below (depending on your install location):

    "C:\Program Files (x86)\Google\Chrome\Application\chrome_restart.bat" OR
    "C:\Program Files\Google\Chrome\Application\chrome_restart.bat"
  1. Right-click in the Command Prompt window. If successful, the script will run and Chrome should close. After a short pause, it should reopen automatically.

Automate It with Task Scheduler

Now it's time to set the script to run every morning automatically at 6am.

  1. Click Start, type task scheduler, and open it.
     
  2. In the left pane, right-click Task Scheduler Library -> Create Task
     
  3. Under the General tab -> Name: Restart Chrome at 6am; Check: Run only when user is logged on, Run with highest privileges, and Hidden
     
  4. Go to the Triggers tab -> Click New: Choose Daily, set time to 6:00 AM, and check Enabled
     
  5. Under Actions tab -> Click New -> Browse; select your .bat file depending on where Chrome is installed:

    "C:\Program Files (x86)\Google\Chrome\Application\chrome_restart.bat" OR
    "C:\Program Files\Google\Chrome\Application\chrome_restart.bat"
     
  6. Under Settings, check Allow task to be run on demand. Click OK to finish.

Final Step: Test It

With Chrome open, go back to Task Scheduler, right-click your "Restart Chrome at 6am" task, and choose Run. If it works, Chrome should close and reopen by itself and Chrome should keep track of which tabs you had opened previously.

Rate this article: 
Average: 5 (8 votes)

Comments

OadbyPC's picture

Were you able to figure out why Chrome was slowing down in the first place? I thought memory leaks had been eliminated by Windows??

What would your recommendation be for a browser other than Chrome?
TIA

Dennis Faas's picture

Generally speaking you should disable all extensions for a few days (a week?) and see if it helps with the bloat without shutting down Chrome. If it still gets bloated after a week, then the problem isn't the extensions, in which case a daily close / reload would help, which is what the script does.