?
Solved

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

Posted on 2008-11-03
2
Medium Priority
?
321 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:mcainc
2 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 1500 total points
ID: 22873436
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
 
LVL 14

Expert Comment

by:Binuth
ID: 22873438
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

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month17 days, 12 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question