How to Check for Memory Leaks in a LotusScript Agent
I ran across this gem in the KnowledgeBase today... you may never need it, but if you do it could be a lifesaver...
------------------
How to Check for Memory Leaks in a LotusScript Agent
Document Number:
1109686
Problem
How can you determine whether a LotusScript agent is leaking memory?
Content
** Note**:
This technote should be distributed on an as-needed
basis only - specifically, only when either you or a customer suspects
that there are memory leaks in a LotusScript agent. The agents included
below are intended to be used only to identify memory leaks in a LotusScript
agent.
If you suspect that a LotusScript agent
is leaking memory, use one of the following scripts to determine whether
memory is indeed not being freed once the agent finishes executing.
The following scripts monitor allocated
memory for each thread. Each executive process takes up one thread.
You need to be aware of this as you are troubleshooting - because
the values may change when a different executive process runs your agent
than the last time it was run. When more than one executive process
is being run on the sever, there is no way to control which thread the
memory check agent will run on. If it runs on a thread other than
the thread that the leaking agent ran on, then the output is irreverent.
When possible, it may be best to limit the number of executive processes
(set in the Server document) to 1 while troubleshooting the leak.
Each memory-checking script should be
placed in an agent to execute before the agent in question and again after
the agent in question. Compare the two sets of numbers. If
the second set of numbers is higher, all memory has not been freed.
If a memory leak is found, isolate the
pieces of the code that are leaking. One way to do this is to break
up the code into smaller pieces. Execute the appropriate leak-checking
agent, then execute the modified agent, then execute the leak-checking
agent again.
Leak-Checking Agents:
I. If the agent is running
in the fore-ground, use the following code:
Sub Initialize
Msgbox(" Total LotusScript Memory Allocated: "
+ (Lsi_info(50)))
Msgbox(" Total LotusScript Memory Allocated from OS:
" + (Lsi_info(51)))
Msgbox(" Total LotusScript Blocks Used: " + (Lsi_info(52)))
End Sub
This agent displays a message box showing
the amount of memory allocated via LotusScript. Remember to run this
code immediately before and after you execute the agent in question - to
compare values and determine whether the agent is indeed leaking memory.
II. If the agent is scheduled, use
the following code:
Sub Initialize
Print "Total LotusScript
Memory Allocated: " + Str$(Lsi_info(50)) + Chr$(10) + Chr$(13)
Print "Total LotusScript Memory Allocated from OS:
" + Str$(Lsi_info(51)) + Chr$(10) + Chr$(13)
Print "Total LotusScript Blocks Used: " + Str$(Lsi_info(52))
+ Chr$(10) + Chr$(13)
End Sub
This agent writes to the server's LOG.NSF
file. Remember to run this code immediately before and after the
agent in question - to compare values and determine whether the agent is
indeed leaking memory.



Comments
Posted by John Marshall At 16:44:17 On 11/12/2003 | - Website - |
Posted by Jerry Carter At 10:54:48 On 11/12/2003 | - Website - |
i recommend using the LScript Function "getThreadInfo()" which is supported by Lotus.
But there are no mem-Params - at least none documented.
Posted by Volker Mannherz At 05:38:03 On 12/12/2003 | - Website - |
Posted by Thomas Duff At 11:08:09 On 11/12/2003 | - Website - |
Comment posted by John Head10/31/2003 10:14:32 AM
While working with Rocky in 1999 as a consultant for the company he was at, and working at that company with him in 2000, I picked up many of these functions. But since 6 was released, there is a new 'undocumented' function lsi_info in my error handler stuff. the following can be done with the funciton:
lsi_info(1) = current line number
lsi_info(2) = current sub/function name
lsi_info(3) = current module
lsi_info(6) = lotusscript version
lsi_info(12) = name of lotuscript function that called this one, to build stack traces
lsi_info(50) = lotusscript memory allocated
lsi_info(51) = lotusscript memory allocated from os
lsi_info(52) = lotusscript blocks used
Its great for getting as much info from the code when the error happens as possible
Posted by Thomas Duff At 12:24:40 On 11/12/2003 | - Website - |
'-----------------------------------------------------------------------------
' File: lsprcval.lss
' Copyright (c) 1997 Lotus Development Corporation
'
' Description: Constants for use with the LSITHREADINFO builtin
'
'-----------------------------------------------------------------------------
public const LSI_THREAD_LINE=0
public const LSI_THREAD_PROC=1
public const LSI_THREAD_MODULE=2
public const LSI_THREAD_VERSION=3
public const LSI_THREAD_LANGUAGE=4
public const LSI_THREAD_COUNTRY=5
public const LSI_THREAD_TICKS=6
public const LSI_THREAD_TICKS_PER_SEC=7
public const LSI_THREAD_PROCESS_ID=8
public const LSI_THREAD_TASK_ID=9
Posted by Thomas Duff At 05:52:36 On 12/12/2003 | - Website - |
Posted by Nathan T. Freman At 11:59:34 On 11/12/2003 | - Website - |
Agent (at start point):
Total LotusScript Memory Allocated: 15744120
Total LotusScript Memory Allocated from OS: 18839068
Total LotusScript Blocks Used: 25272
Agent (at end point)
Total LotusScript Memory Allocated: 15839992
Total LotusScript Memory Allocated from OS: 18880028
Total LotusScript Blocks Used: 25553
Posted by Jack At 10:38:05 On 15/03/2010 | - Website - |
Posted by Jack At 11:46:48 On 15/03/2010 | - Website - |