Results 1 to 7 of 7

Thread: Little Tip For Everyone

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    34

    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....

    AKA 'Lethal'

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    34
    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.
    AKA 'Lethal'

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    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?

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    34
    Because the path of execution left the with block before the ending 'End With', it for some reason still holds the reference.
    AKA 'Lethal'

  6. #6
    Addicted Member Cimperiali's Avatar
    Join Date
    Oct 2002
    Location
    Milan, Italy, Europe
    Posts
    188

    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....
    Special thanks to some wonderful people,
    such as Lothar the Great Haensler, Aaron Young,
    dr_Michael, Chris Eastwood, TheOnlyOne ClearCode....

  7. #7
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Yep, I found out the hard way..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width