Alex Gordon
Alex Gordon

Reputation: 60751

vb.net: clearing all contents of string array

i have this:

    Dim split As String() = temp_string.Split(",")

    ''#feed all info into global variables
    patient_id = split(0)
    doc_name = split(1)
    lot__no = split(2)
    patient_name = split(3)

how do i clear all the contents of split() ?

Upvotes: 6

Views: 32443

Answers (4)

Sean
Sean

Reputation: 381

No need to do anything. The garbage collector will do its jobs clearing the variable. Explicitly set every variable to nothing will slow down your application.

Upvotes: 5

Fredrik Mörk
Fredrik Mörk

Reputation: 158309

You can always set it to Nothing which will clear the reference. Then the garbage collector will take care of the rest when it finds that to be a good idea.

split = Nothing

However, if this is a local variable of a method you would typically not need to worry about this, the array will be available for garbage collection as soon as it goes out of scope.

Upvotes: 4

xpda
xpda

Reputation: 15813

ReDim split(-1)

Upvotes: 8

ChaosPandion
ChaosPandion

Reputation: 78272

Array.Clear(split, 0, split.Length)

Upvotes: 13

Related Questions