十八、垃圾收集函数
垃圾收集函数让应用程序能够控制何时开始收集系统产生的垃圾。
1、GarbageCollect()
功 能:强制系统立即开始收集垃圾。
语 法:GarbageCollect ( )
返回值:无。
用 法:该函数强制系统立即开始收集垃圾。PowerBuilder将查找并标识未使用的对象,包括循环引用的变量,然后删除这些对象以及相应的类。
示 例:下面这段代码让系统立即开始收集垃圾。
GarbageCollect()
2、GarbageCollectGetTimeLimit()
功 能:得到当前收集的最小时间间隔。
语 法:GarbageCollectGetTimeLimit ( )
返回值:Long。返回当前收集垃圾的最小时间间隔。
用 法:返回两次垃圾收集之前的最短时间间隔。
示 例:This statement returns the interval between garbage collection passes in the variable
CollectTime:
long CollectTime
CollectTime = GarbageCollectGetTimeLimit()
3、GarbageCollectSetTimeLimit()
功 能:设置垃圾收集操作之间的最小时间间隔。
语 法:GarbageCollectSetTimeLimit ( newtime )
参 数:newtime:Long类型,指定两次垃圾收集之间的最短时间间隔(以毫秒为单位)。如果该参数的值为NULL,原间隔时间不变。
返回值:Long。返回调用该函数前垃圾收集的最短时间间隔。如果参数newtime的值为NULL,则函数返回
NULL,原时间间隔不变。。
用 法:如果把垃圾收集的时间间隔设置很大,就相当于关闭了垃圾收集功能,这样,未使用的类就不会被清除出类缓冲区。
示 例:This example sets the interval between garbage collection passes to 1 second and sets the variable OldTime to the length of the previous interval:
long OldTime, NewTime
NewTime = 1000 /* 1 second */
OldTime = GarbageCollectSetTimeLimit(NewTime)