Declare Your Objects Properly

Never declare a variable as a “New” of type “object,” but always rather just as of type “object.” If you do so you will always increment the reference count of the object, even though you do not use it. Also, always remember to set your objects to nothing when finished. The wrong way is:

 Private Sub Foo()    Dim oCust as New clsCust    'do stuff with oCustEnd Sub

The right way is:

 Private Sub Foo()    Dim oCust as clsCust    Set oCust = New clsCust    'do stuff with oCust    Set oCust = NothingEnd Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: