ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Does VBA have a garbage collector? (https://www.excelbanter.com/excel-programming/419229-does-vba-have-garbage-collector.html)

RyanH

Does VBA have a garbage collector?
 
I am starting to learn VB.NET. I know VB.NET has garbage collection so you
don't have to destroy the object in code. Does VBA have a form of garbage
collection or is it best to destroy the object manually in code?
--
Cheers,
Ryan

Peter T

Does VBA have a garbage collector?
 
Yes. Typically I'm sure it's fine, if not better, to let VB's garbage
collection destroy objects naturally when they are about to fall out of
scope (eg procedure level objects as the procedure terminates).

You will still need to destroy static or module level objects when done.
Also there are certain scenarios that lead to circular references where a
particular object will need to be released first (probably a rare scenario
in VBA).

Some prefer to explicitly destroy all objects but that's more a matter of
style.

Regards,
Peter T



"RyanH" wrote in message
...
I am starting to learn VB.NET. I know VB.NET has garbage collection so you
don't have to destroy the object in code. Does VBA have a form of garbage
collection or is it best to destroy the object manually in code?
--
Cheers,
Ryan





All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com