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
Try
    ...
    Return aList
Finalize
    aList = nothing
End Try

is there a better way to do this?
mcaincAsked:
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
0
 
BinuthCommented:
not Finalize use Finally
        Dim aList As New ArrayList
        Try
            Return aList
        Catch ex As Exception
 
        Finally
            aList = Nothing
        End Try

Open in new window

0
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.