COM Object Cleanup

◇◆丶佛笑我妖孽 提交于 2019-12-05 22:38:50

COM will keep processes in memory for a while after the last reference is gone, just in case you want to create another object requiring the same process soon afterwards.

The theory is that process creation is very slow and expensive, and you might inadvertently write a loop or something that does this:

 While 1=1

      Set a = CreateObject(...)
      ' Later
      Set a = Nothing

 Wend

You wouldn't want Windows thrashing around killing and launching processes endlessly in the loop.

Eventually they go away.

In VBA the command to release an object is

Set o = Nothing

You have a weak reference to the created object, Raz function return value, that maintains the object instance.

Variable o is automatic and referenced object is automatically set to nothing when function returns, but you are assigning value to Raz and probably to client code so the instanced value is not disposed on function return.

Furthermore, if the object, as it happens, reference a user control, you probably can't unload the user form containing it.

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