JSI Tip 3467. Is there a Workaround for a service which leaks memory?


If you have a service that leaks memory, I have scripted a general purpose workaround, until the author provides a fix.

The MemoryLeak script use the Tlist freeware:

Windows NT 4.0 - 1388 » Where are the SP4+ Free Resource Kit Tools?

Windows 2000 - From the Support Tools on the Windows 2000 CD-ROM.Run Tlist manually for the leaky process, and determine your threshold for PeakWorkingSetSize. Then schedule MemoryLeak.bat to run as infrequently as you can afford. The syntax is:

MemoryLeak Process PeakWorkingSetSize ServiceShortName

where:

Process             - Is the process name as displayed by Tlist, generally xxxxxx.exe.
PeakWorkingSetSize  - Is the maximum value before the process is stopped and restarted.
ServiceShortName    - See tip 3444 » How do I find the short name of a service?
NOTE: If when you manually stop this service, it stops other services, you will need to make a custom version of the MemoryLeak script.

MemoryLeak.bat contains:

@echo off
setlocal
if \{%1\}

\{\} goto syntax if \{%2\}

\{\} goto syntax if \{%3\}

\{\} goto syntax set process=%1 set trigger=%2 set ssn=%3 set process=%process:"=% set trigger=%trigger:"=% set /a trigger=%trigger% if %trigger% EQU 0 goto syntax set PID=NNN for /f "Tokens=1-2" %%i in ('Tlist') DO call :find %%i %%j if "%PID%"

"NNN" goto syntax for /f "Tokens=*" %%i in ('Tlist %PID%') DO call :Size "%%i" endlocal goto end :syntax @echo Syntax: MemoryLeak Process PeakWorkingSetSize ServiceShortName endlocal goto end :find if /i not "%2"

"%process%" goto end set PID=%1 set PID=%PID: =% goto end :Size set wrkset=%1 set wrkset=%wrkset:"=% for /f "Tokens=1,5" %%j in ('@echo %wrkset%') DO call :check "%%j" %%k goto end :check if not %1

"WorkingSetSize:" goto end set /a pwss=%2 if %pwss% LSS %trigger% goto end net stop %ssn% net start %ssn% :end



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish