1

The NotesUserActivity class appears to have a memory leak. When I collect the user activity information from multiple databases and call the GetNthUserActivityEntry method, the memory usage increases with every call.

I found a few references to this issue, but no solution. I think the issue is related to this call:

' Load the User name for the Activity Structure
UsernameOffset = puActivity + puActivityEntry.UserNameOffset
spUsername = Space(MAXUSERNAME)
Call CopyMemoryString(spUsername, UsernameOffset,Lenb(spUsername))
sUserName = Left(spUsername, Instr(spUsername, Chr(0)) - 1)
Jasper Duizendstra
  • 2,587
  • 1
  • 21
  • 32

2 Answers2

2

The username is fetched from the memory by reading MAXUSERNAME bytes (256). The username is usually not 256 bytes long, so I think the function accesses memory that it should not access.

I changed code to:

Call CopyMemoryString(spUsername, UsernameOffset, strlenLP(UsernameOffset))
Dim sUsername As String
sUserName = Trim(spUsername)

The strlenLP() method reads the memory until it reaches a \0. The declaration is:

Declare Private Function lstrlenLP Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Jasper Duizendstra
  • 2,587
  • 1
  • 21
  • 32
  • Did this correct the leak? I looked at the code for the class, and while I didn't see anything else that looked suspicious, I really doubt that the CopyMemoryString call could be causing a leak because it doesn't allocate anything. It is copying from the memory that was allocated by the C API (UsernameOffset) into the memory that was allocated by the LotusScript runtime for a fixed length string (spUsername). – Richard Schwartz Jun 05 '12 at 23:52
  • The change I made: Lenb(spUsername) became strlenLP(UsernameOffset). With Lenb(spUsername) the CopyMemoryString call reads 256 bytes in all cases, with strlenLP(UsernameOffset) it returns at all data up to the the position of the \0. It is not Copymemorystring itself I suspect, it is the way it is being used. – Jasper Duizendstra Jun 06 '12 at 07:08
  • There is a post in Notes forum on developerWorks today that announces a new release of the class. See here: http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllFlatWeb/BF9AECFB621CC3CD85257A1E000D317B?OpenDocument&ca=drs-fo – Richard Schwartz Jun 15 '12 at 04:29
  • The new version contains the change I made. Case closed :-) – Jasper Duizendstra Jun 15 '12 at 07:53
0

It is a shot in the dark, but in my experience the GetNth... Methods in Notes are very inefficient. Is there a way to iterate using GetFirst / GetNext like there is for most Notes objects? I'd see if that helps.

Ken Pespisa
  • 21,989
  • 3
  • 55
  • 63
  • This is a different GetNth... It is not a standard Lotus class but a class provided by http://www.agecom.com.au/useractivity. It is based on an older class from the Sandbox. – Jasper Duizendstra Jun 05 '12 at 21:44