-
Little Tip For Everyone
I just want to share a tip with all of you, b/c it burnt me and wasted a few hours of my time.
I was using a third party, ActiveX EXE and every so often, it was cause a huge memory leak. I checked all my references, made sure they were being destroyed, as well as making sure no circular ref's were present. Here is the scenario that got me:
Code:
On Error Goto ErrorHandler
Dim objExtra As New Extra.Session
With objExtra
' do some calculation and login routines....
If objExtra.Value <> 0 Then
Err.Raise vbObjectError + 7000
End If
End With
Set objExtra = Nothing
Exit Sub
ErrorHandler:
objExtra = Nothing
Err.Raise Err.Number
Hence, my routine in actuallity was much larger than this small sample. Well, b/c I raised an error within the with block, the object's reference count is incremented, thus will not release from memory when set to nothing.
Just something to watch out for....
:eek:
-
I don't understand. You have objExtra = Nothing in the error trap. Isn't that enough?
-
Nope. Because the error is raised within the with block. Strange, but I tested a few other scenario's like this one, and they all came out the same.
-
I still don't understand. When the error is raised within the block the next line of code that is executed is the first line of code in the error routine. I think that line should be Set objExtra = Nothing and that will get rid of the reference won't it?
-
Because the path of execution left the with block before the ending 'End With', it for some reason still holds the reference.
-
With...End With locks
Accordingly to author of "Advanced Vb" (If I remember corectly...)
with...end with has a side effect on objects: it locks them....
-
Yep, I found out the hard way..:D