I have found what seems to be be strange behavior in VB6. If I declare an object at the class level, when I try to destroy it, it takes a very long time, 80 seconds. But if I declare this object within a Sub and destroy it releases the memory in less than one second. This object reads in a 5mb file. Below is some code and the output:
Public m_objDataObject As MyObject
Private Sub cmdCreateandDestory_Click()
'' Test Local Object create and destoy
Dim dtmStartTime As Date
Dim dtmDiff As Date
Debug.Print "Creating local object"
dtmStartTime = Now
Dim objMyObject As MyObject
Set objMyObject = New MyObject
objMyObject.LoadData
Debug.Print " Creation took " + CStr(DateDiff("s", dtmStartTime, DateTime.Now)) + " secs"
dtmStartTime = DateTime.Now
Debug.Print " Destroying local object"
Set objMyObject = Nothing
Debug.Print " Destroying local object took " + CStr(DateDiff("s", dtmStartTime, DateTime.Now)) + " secs"
Debug.Print
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Test global create and destroy
Debug.Print "Creating class object"
dtmStartTime = Now
Set m_objDataObject = New MyObject
m_objDataObject.LoadData
Debug.Print " Creation took " + CStr(DateDiff("s", dtmStartTime, DateTime.Now)) + " secs"
dtmStartTime = DateTime.Now
Debug.Print " Destroying global object"
Set m_objDataObject = Nothing
Debug.Print " Destroying global object took " + CStr(DateDiff("s", dtmStartTime, DateTime.Now)) + " secs"
End Sub
Creating local object
Loading data from file took 0 secs
7/21/2008 11:36:29 AM
Creation took 7 secs
Destroying local object
Destroying local object took 0 secs
Creating global object
Loading data from file took 1 secs
7/21/2008 11:36:40 AM
Creation took 11 secs
Destroying global object
Destroying global object took 78 secs