JSI Tip 3467. Is there a Workaround for a service which leaks memory?
Jerold Schulman
March 12, 2001
1 Min Read
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 offsetlocalif {%1}
{} goto syntaxif {%2}
{} goto syntaxif {%3}
{} goto syntaxset process=%1set trigger=%2set ssn=%3set process=%process:"=%set trigger=%trigger:"=%set /a trigger=%trigger%if %trigger% EQU 0 goto syntaxset PID=NNNfor /f "Tokens=1-2" %%i in ('Tlist') DO call :find %%i %%jif "%PID%"
"NNN" goto syntaxfor /f "Tokens=*" %%i in ('Tlist %PID%') DO call :Size "%%i"endlocalgoto end:syntax@echo Syntax: MemoryLeak Process PeakWorkingSetSize ServiceShortNameendlocal goto end:findif /i not "%2"
"%process%" goto endset PID=%1set PID=%PID: =%goto end:Sizeset wrkset=%1set wrkset=%wrkset:"=%for /f "Tokens=1,5" %%j in ('@echo %wrkset%') DO call :check "%%j" %%kgoto end:checkif not %1
"WorkingSetSize:" goto endset /a pwss=%2if %pwss% LSS %trigger% goto endnet stop %ssn%net start %ssn%:end
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like