COM(ActiveX)は、作成されたオブジェクトをダイナミックに破棄するメカニズムがないので、SFC miniでも一度作成したオブジェクトは破棄できません。SFC miniオブジェクトの取得とリリースを、メモリーリークを起こすことなく繰り返し行ないたい場合は、少し工夫が必要です。要らなくなったオブジェクトはリセットを行ない、もう一度使うようにします。具体的な方法は、サンプルコードを参照して下さい。

サンプルコード

VBScript
option explicit

Dim i,j,dfactory,sfactory,dobj,sobj,result
Set dfactory=New dynacall
Set sfactory=New structure

For j=1 To 2
  MsgBox "Start " & j
  For i=1 To 10000
    Set dobj=dfactory.NewObject()
    dobj.Declare "kernel32","GetCurrentDirectoryA"
    result=dobj(0,0)
    Set sobj=sfactory.NewObject()
    sobj "str","String*"&result
    dobj result,sobj
    result=sobj.str
    ' If you comment-out next two lines, memory-usage will increase dramatically
    dfactory.DeleteObject(dobj)
    sfactory.DeleteObject(sobj)
  Next
Next

MsgBox "End. " & result

' dynacall class to construct "SfcMini.Dynacall" object
Class dynacall
Private deleted,deletedNum
Private Sub Class_Initialize()
  ReDim deleted(0)
  deletedNum=0
End Sub
Public Function NewObject()
  If 0<deletedNum Then
    deletedNum=deletedNum-1
    Set NewObject=deleted(deletedNum)
    ReDim Preserve deleted(deletedNum)
  Else
    Set NewObject=WScript.CreateObject("SfcMini.Dynacall")
  End If
End Function
Public Sub DeleteObject(ByRef obj)
  call obj.Reset()
  Set deleted(deletedNum)=obj
  deletedNum=deletedNum+1
  ReDim Preserve deleted(deletedNum)
End Sub
End Class

' structure class to construct SfcMini.Structure object
Class structure
Private deleted,deletedNum
Private Sub Class_Initialize()
  ReDim deleted(0)
  deletedNum=0
End Sub
Public Function NewObject()
  If 0<deletedNum Then
    deletedNum=deletedNum-1
    Set NewObject=deleted(deletedNum)
    ReDim Preserve deleted(deletedNum)
  Else
    Set NewObject=WScript.CreateObject("SfcMini.Structure")
  End If
End Function
Public Sub DeleteObject(ByRef obj)
  call obj("Reset")
  Set deleted(deletedNum)=obj
  deletedNum=deletedNum+1
  ReDim Preserve deleted(deletedNum)
End Sub
End Class