Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does VBA provide garbage collection for String and Array?

Tags:

macos

ms-word

vba

I am beginner in VBA. I have created a Template in Word (.dotm). I have used 30 String object. I don't know whether VBA dispose it or do I need to dispose it manually.

Can anybody please suggest me so I will not have problem of memory in future?

like image 466
Nanji Mange Avatar asked Jan 22 '26 20:01

Nanji Mange


1 Answers

No need to dispose. As soon as the string variable is out of scope, the memory is recovered.

'Globally scoped g will be retained until the project is reset with `End`
Public g as string

Sub foo()
  Dim s as string
  s = "foo"

  g = "bar"

's is destroyed on exiting the sub
End Sub

Sub bar()
  ' Reset the project will reclaim all variables including Globals
  End
End Sub
like image 119
ThunderFrame Avatar answered Jan 25 '26 13:01

ThunderFrame



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!