Freeing Dynamic Arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • headware

    Freeing Dynamic Arrays

    Do you have to manually release memory allocated by creating a dynamic
    array using ReDim? In other words, if I have the following code:

    ReDim Test(1000)
    For i = 0 To 1000
    Test(i) = "test value " & i
    Next

    Do have I have set Test = Nothing to prevent a memory leak?

    Thanks,
    Dave
  • Peter Bromberg [C# MVP]

    #2
    Re: Freeing Dynamic Arrays

    Firstly, arrays as you describe them are not "dynamic" - the VB.NET "Redim"
    keyword simply creates a new array and copies the contents to it.
    When an array goes out of scope, it is marked for garbage collection, so you
    do not need to do anything.
    Peter

    "headware" <david.k.land@g mail.comwrote in message
    news:a7e2fa67-a37b-4a98-bbda-ecf69bdcea04@56 g2000hsm.google groups.com...
    Do you have to manually release memory allocated by creating a dynamic
    array using ReDim? In other words, if I have the following code:
    >
    ReDim Test(1000)
    For i = 0 To 1000
    Test(i) = "test value " & i
    Next
    >
    Do have I have set Test = Nothing to prevent a memory leak?
    >
    Thanks,
    Dave

    Comment

    Working...