Is object clearing/array deallocation really necessary in VB6/VBA (Pros/Cons?)

前端 未结 5 2465
暗喜
暗喜 2021-02-20 12:33

A lot of what I have learned about VB I learned from using Static Code Analysis (Particularly Aivosto\'s Project Analyzer). And one one of things it checks for is whether or not

5条回答
  •  鱼传尺愫
    2021-02-20 13:02

    Matt Curland, author of Advanced Visual Basic 6, who knows more about Visual Basic than most of us ever will, thinks it is wasted effort. Consider this quote (p110) about DAO, the COM data access library that primarily targets the Access Database Engine:

    another example of poor teardown code. DAO has Close methods that must be called in the correct order, and the objects must be released in the correct order as well (Recordset before Database, for example). This single poor object model behavior has led to the misconception that VB leaks memory unless you explicitly set all the local variables to nothing at the end of a function. This is a completely false notion in a well-designed object model. VB can clear the variables faster at the End Sub line than you can from code, and it checks the variables even if you explicitly release your references. Any effort you make is duplicated.

提交回复
热议问题