Forcing Garbage Collection

我怕爱的太早我们不能终老 提交于 2020-01-12 16:08:11

问题


Is there a way to force garbage collection in VBA/Excel 2000?

This question refers to the Macro language in Excel. Not using VB .NET to manipulate Excel. So GC.collect() won't work


回答1:


You cannot take advantage of garbage collection provided by the .NET Framework when using straight VBA. Perhaps this article by Eric Lippert will be helpful




回答2:


You can't force GC in VBA, but it's good to set to Nothing the global variables.

The article mentioned by kd7 says it's useless to set to Nothing the local variables before they go out of scope, but doesn't talk about the global variables.

In VBA the global variables defined in a module remain alive through the whole Excel session, i.e. until the document containing the VBA module that defines them closed.

So don't put useless Set O = Nothing when O is local, but do it when it's global.




回答3:


VBA/Excel does not have garbage collection, like old VB. Instead of GC, it uses reference counting. Memory is freed when you set a pointer to nothing (or when variable goes out of scope). Like in old VB it means that circular references are never freed.



来源:https://stackoverflow.com/questions/1775470/forcing-garbage-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!