Nanji Mange
Nanji Mange

Reputation: 2265

Does VBA provide garbage collection for String and Array?

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?

Upvotes: 3

Views: 508

Answers (1)

ThunderFrame
ThunderFrame

Reputation: 9461

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

Upvotes: 4

Related Questions