VB.NET can you execute code AFTER Return in a function?

I have a function that creates an arraylist & returns it... however after it is returned I want to make the arraylist variable = nothing

I get a warning with that a value isn't returned on all code paths

Dim aList as New ArrayList
    Return aList
    aList = nothing
End Try

is there a better way to do this?
Who is Participating?
Gyanendra SinghConnect With a Mentor ArchitectCommented:
no... this piece of code will not work..  you dontworry about your arraylist ... anyway it is local variable and garbage collector will take care of this ...

also arraylist is object and object always have reference type so anything you will change in object it will reflect in your code .. so better dont set nothin ... let garbage collector will do its job
not Finalize use Finally
        Dim aList As New ArrayList
            Return aList
        Catch ex As Exception
            aList = Nothing
        End Try

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.