Garbage collection is done with three characteristics in Lotusscript.
a) It’s done after the execution of EACH line of code.
b) It reclaims the memory of an object when on local variable references it directly, even when another referenced object links to it.
c) When it reclaims an object, it reclaims all the objects contained by the object. Notes does not allow free-floating objects that exist outside their container, or "owner" object. Documents, for example, must belong to a database. Items must belong to a document,
and ACLEntries must belong to an ACL object.
Point a) ensures the efficient memory usage when a sub involves the iteration of a large number of Notes objects e.g. documents.
set view = db.GetView("$all")
set doc = view.GetFirstDocument()
while not (doc is nothing)
' do something...
set doc = view.GetNextDocument(doc)
wend
Point b) and c) are harmful when they work together.
dim s as new NotesSession
dim entry as NotesEntry
set entry = s.CurrentDatabase.ACL.GetFirstEntry
The entry object will be reclaimed right after the assignment statement is executed as the ACL object is not stored in any variable and thus destructed, which causes the child object ACLEntry
to be reclaimed. The issue in this case can be fixed by storing the ACL object in a variable.
Another case is as below:
Sub Initialize
Dim s As New NotesSession
Dim view As NotesView
Set view=TestObj()
Print view.Name
End Sub
Function TestObj As NotesView
Dim s As New NotesSession
Dim db As NotesDatabase
Set db=s.Getdatabase(s.Currentdatabase.Server, "log.nsf")
Set TestObj=db.Getview("UsageByUser")
End function
The View object returned by the function TestObj is reclaimed before it can be used by the caller because the parent database log.nsf is reclaimed after the function ends. If the view is from the current database, it will keep alive, even if
the current database object is not initialized in the caller. The current session and database objects keep alive until the whole program e.g. agent exits. To avoid the failure above, a global variable can be declared to hold the exterior database object.
Sub Initialize
Dim s As New NotesSession
‘the following two lines are optional
Dim db As NotesDatabase
Set db=s.Currentdatabase
Dim view As NotesView
Set view=TestObj()
Print view.Name
End Sub
Function TestObj As NotesView
Dim s As New NotesSession
Set TestObj=s.Currentdatabase.Getview("All")
End function
分享到:
相关推荐
系统级编程课程的垃圾回收实验 有代码与文档说明
垃圾回收算法的经典之作。 本书围绕着动态内存自动回收的话题,介绍了垃圾收集机制,详细分析了各种算法和相关技术。 本书共12章。第1章首先介绍计算机存储器管理的演化和自动内存回收的需求,并引入了本书所使用...
著名的C/C++垃圾回收站
The Garbage Collection Handbook:The Art of Automatic Memory Manage
The Garbage Collection Handbook The Art of Automatic Memory Management, Jones, Hosking, Moss, 2012
The Garbage Collection Handbook 内存管理,垃圾收集,GC
The Garbage Collection Handbook 关于垃圾回收器算法的书籍,非常不错
The Java Platform, Standard Edition HotSpot Virtual Machine Garbage Collection Tuning Guide describes the garbage collection methods included in the Java HotSpot Virtual Machine (Java HotSpot VM) and ...
The Garbage Collection Handbook The Art of Automatic Memory Management 英文epub
严蔚敏数据结构与算法▲课本算法实现
Garbage Collection Algorithms For Automatic Dynamic Memory Management
The Garbage Collection Cookbook 垃圾回收算法手册
Java Garbage Collection Basics
在JVM5.0中调配Garbage Collection 在JVM5.0中调配Garbage Collection 在JVM5.0中调配Garbage Collection
WP-Understanding Java Garbage Collection
Understanding_Java_Garbage_Collection_v4.pdf 理解 java 垃圾收集 PDF
12.6.5 “Garbage collecting the world” 12.6.6 网络对象 12.6.7 带权引用计数 12.6.8 世代引用计数 12.7 对actor进行垃圾收集 12.7.1 Halstead算法 12.7.2 标记算法 12.7.3 逻辑上集中式的收集器 12.8 引文注记
内含四大类(可回收、厨余、其他、有害)垃圾图片及分类信息,共分为40小类垃圾(如"其他垃圾/破碎花盆及碟碗"、"其他垃圾/牙签"、"厨余垃圾/水果果皮"、"可回收物/易拉罐"、"可回收物/纸板箱"、"有害垃圾/干电池"等...
Lock-free Parallel Garbage Collection