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

Posted on 2008-11-03
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
    Return aList
    aList = nothing
End Try

is there a better way to do this?
Question by:mcainc
    LVL 16

    Accepted Solution

    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
    LVL 14

    Expert Comment

    not Finalize use Finally
            Dim aList As New ArrayList
                Return aList
            Catch ex As Exception
                aList = Nothing
            End Try

    Open in new window


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now