Schedule Agent - Out of memory

Since upgrading from R5 to 6.5 most of our scheduled agents run out of memory. I read a few posts recommending that we use the Delete statement to free up memory, but none explain how to use it in detail.

Here is the code for one of my agents. Could someone please tell me where to use the delete statement and explain exactly what it will do to fix the issue.

Sub Initialize

Dim session As New notessession

Dim db As notesdatabase 

Dim vw As notesview

Dim viewdoc As notesdocument



Set db=session.currentdatabase

Set vw=db.getview("CompletionInformation")

Set viewdoc=vw.getfirstdocument



Dim newdoc As NotesDocument



On Error Resume Next		

Do Until viewdoc Is Nothing

'Create Response Document

	Set newdoc = db.CreateDocument	

	Call newdoc.MakeResponse( viewdoc )

	

	newdoc.Form = "CompletionInformation"	

	newdoc.RequestID = viewdoc.RequestID

	newdoc.RequestDate = viewdoc.RequestDate

	newdoc.ResponsiblePerson = viewdoc.ResponsiblePerson	

	newdoc.ResponsiblePerson2 = viewdoc.ResponsiblePerson2

	newdoc.CellPhone = viewdoc.CellPhone

	newdoc.CellPhone2 = viewdoc.CellPhone2		

	newdoc.TestPerson = viewdoc.TestPerson

	newdoc.DateTested = viewdoc.DateTested

	newdoc.QualityControl = viewdoc.QualityControl

	newdoc.StartDate = viewdoc.StartDate

	newdoc.EndDate = viewdoc.EndDate

	newdoc.StartTime = viewdoc.StartTime

	newdoc.EndTime = viewdoc.EndTime

	newdoc.ChangeType = viewdoc.ChangeType

	newdoc.RemoteChange = viewdoc.RemoteChange

	newdoc.EffectedSystems = viewdoc.EffectedSystems

	newdoc.ChangeLocation = viewdoc.ChangeLocation

	newdoc.ServerName = viewdoc.ServerName

	newdoc.EffectedLocations= viewdoc.EffectedLocations

	newdoc.ServerDescription = viewdoc.ServerDescription

	newdoc.ManagerOnSite = viewdoc.ManagerOnSite

	newdoc.Priority = viewdoc.Priority

	newdoc.PriorityDate= viewdoc.PriorityDate

	newdoc.ManagedServiceProvider = viewdoc.ManagedServiceProvider

	newdoc.ChangeDescription = viewdoc.ChangeDescription

	newdoc.FallbackProcedures = viewdoc.FallbackProcedures

	newdoc.AddComments = viewdoc.AddComments

	

	Call newdoc.save(False,True)

'Added to refresh form

	Call newdoc.ComputeWithForm(True,False)

	Call newdoc.save(True,False)

'Send Email

	Dim workspace As New NotesUIWorkspace

	

	Dim doc As NotesDocument

	Dim rtitem As NotesRichTextItem

	

	Set doc = New NotesDocument( db )

	Set rtitem = New NotesRichTextItem( doc, "Body" )

	

	doc.Subject = "Change Management Needs Completion Information"

’ doc.Principal = “STV Helpdesk/STV”

’ doc.ReplyTo = “STV Helpdesk/STV”

	Call rtitem.AddNewLine( 1)

	Call rtitem.AppendText( "The attached change management request needs completion information.")

	Call rtitem.AddNewLine( 2)

	Call rtitem.AppendText( "Select the link below to complete and submit this information immediately.")

	Call rtitem.AddNewLine( 3 )	

	Call rtitem.AppendText( "Link to Change Completion Document ----->>>>>> " )

	Call rtitem.AppendDocLink( newdoc, db.Title )	

	Call rtitem.AddNewLine( 3 )	

	Call rtitem.AppendText( "Thank you.")

	

	Call doc.Send( False,  newdoc.ResponsiblePerson)

'Mark original form that completion form was sent

	viewdoc.CompletionFormSent="Yes"

	Call viewdoc.save(True,False)

'Loop

	Set viewdoc=vw.getnextdocument(viewdoc)

	

Loop

End Sub

Subject: Schedule Agent - Out of memory

change code as follows

Sub Initialize

Dim session As New notessession

Dim db As notesdatabase

Dim vw As notesview

Dim viewdoc As notesdocument

Set db=session.currentdatabase

Set vw=db.getview(“CompletionInformation”)

Set viewdoc=vw.getfirstdocument

'RELOCATED HERE

'YOU DO NOT NEED THIS THE WAY CODE IS RUNNING

'Dim workspace As New NotesUIWorkspace

Dim doc As NotesDocument

Dim rtitem As NotesRichTextItem

'END RELOCATION

Dim newdoc As NotesDocument

On Error Resume Next

Do Until viewdoc Is Nothing

'Create Response Document

Set newdoc = db.CreateDocument

Call newdoc.MakeResponse( viewdoc )

newdoc.Form = “CompletionInformation”

newdoc.RequestID = viewdoc.RequestID

newdoc.RequestDate = viewdoc.RequestDate

newdoc.ResponsiblePerson = viewdoc.ResponsiblePerson

newdoc.ResponsiblePerson2 = viewdoc.ResponsiblePerson2

newdoc.CellPhone = viewdoc.CellPhone

newdoc.CellPhone2 = viewdoc.CellPhone2

newdoc.TestPerson = viewdoc.TestPerson

newdoc.DateTested = viewdoc.DateTested

newdoc.QualityControl = viewdoc.QualityControl

newdoc.StartDate = viewdoc.StartDate

newdoc.EndDate = viewdoc.EndDate

newdoc.StartTime = viewdoc.StartTime

newdoc.EndTime = viewdoc.EndTime

newdoc.ChangeType = viewdoc.ChangeType

newdoc.RemoteChange = viewdoc.RemoteChange

newdoc.EffectedSystems = viewdoc.EffectedSystems

newdoc.ChangeLocation = viewdoc.ChangeLocation

newdoc.ServerName = viewdoc.ServerName

newdoc.EffectedLocations= viewdoc.EffectedLocations

newdoc.ServerDescription = viewdoc.ServerDescription

newdoc.ManagerOnSite = viewdoc.ManagerOnSite

newdoc.Priority = viewdoc.Priority

newdoc.PriorityDate= viewdoc.PriorityDate

newdoc.ManagedServiceProvider = viewdoc.ManagedServiceProvider

newdoc.ChangeDescription = viewdoc.ChangeDescription

newdoc.FallbackProcedures = viewdoc.FallbackProcedures

newdoc.AddComments = viewdoc.AddComments

Call newdoc.save(False,True)

'Added to refresh form

Call newdoc.ComputeWithForm(True,False)

Call newdoc.save(True,False)

'Send Email

Set doc = New NotesDocument( db )

Set rtitem = New NotesRichTextItem( doc, “Body” )

doc.Subject = “Change Management Needs Completion Information”

’ doc.Principal = “STV Helpdesk/STV”

’ doc.ReplyTo = “STV Helpdesk/STV”

Call rtitem.AddNewLine( 1)

Call rtitem.AppendText( “The attached change management request needs completion information.”)

Call rtitem.AddNewLine( 2)

Call rtitem.AppendText( “Select the link below to complete and submit this information immediately.”)

Call rtitem.AddNewLine( 3 )

Call rtitem.AppendText( "Link to Change Completion Document ----->>>>>> " )

Call rtitem.AppendDocLink( newdoc, db.Title )

Call rtitem.AddNewLine( 3 )

Call rtitem.AppendText( “Thank you.”)

Call doc.Send( False, newdoc.ResponsiblePerson)

'Mark original form that completion form was sent

viewdoc.CompletionFormSent=“Yes”

Call viewdoc.save(True,False)

'REINIT JUST TO BE SURE IT IS CLEAN AS LOOP STARTS

Set doc = nothing

set rtitem=nothing

'Loop

Set viewdoc=vw.getnextdocument(viewdoc)

Loop

Try that and respond to us

Subject: RE: Schedule Agent - Out of memory

Thanks for the tips but I am still getting out of memory when running this on a schedule.