Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 60497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:10:16+00:00 2026-05-10T18:10:16+00:00

I am working on a web application and I have run into the following

  • 0

I am working on a web application and I have run into the following situation.

Dim a as Object Dim i as Integer = 0  Try      For i=1 to 5          a = new Object()          'Do stuff '          a = Nothing      Next  Catch  Finally     a = Nothing  End Try 

Do i need to do the a=Nothing in the loop or will the garbage collector clean a up?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:10:17+00:00Added an answer on May 10, 2026 at 6:10 pm

    In .NET, you generally do not need to set a variable reference = Nothing (null in C#). The garbage collector will clean up, eventually. The reference itself will be destroyed when it goes out of scope (either when your method exits or when the object of this class is finalized.) Note that this doesn’t mean the object is destroyed, just the reference to it. The object will still be destroyed non-deterministically by the collector.

    However, setting your reference = Nothing will provide a hint to .NET that the object may be garbage, and doesn’t necessarily hurt anything — aside from code clutter. If you were to keep it in there, I’d recommend removing it from Try block; it’s already in the Finally block and will therefore always be called. (Aside from certain catastrophic exceptions; but in those cases it wouldn’t get called in the Try block either!)

    Finally, I have to admit that I agree with Greg: Your code would be cleaner without this. The hint to the runtime that you’re done with the reference is nice, but certainly not critical. Honestly, if I saw this in a code review, I’d probably have the developer rewrite it thusly:

    Dim a as Object Dim i as Integer = 0  For i=1 to 5     a = new Object()     'Do stuff Next 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 237k
  • Answers 237k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In Java arguments are passed by value, object arguments pass… May 13, 2026 at 6:36 am
  • Editorial Team
    Editorial Team added an answer Try something like this <Style x:Key="textboxPasswordboxStyles"> <Setter Property="Control.ControlProperty" Value="value" />… May 13, 2026 at 6:36 am
  • Editorial Team
    Editorial Team added an answer class My_Service_XYZ { public function test() { $h = Zend_Controller_Action_HelperBroker::getStaticHelper('Host');… May 13, 2026 at 6:36 am

Related Questions

I am working on a Web Forms application and I have some HTML code
I am working on a web application (J2EE) and I would like to know
I am working on a web application that will deal with many image uploads.
I am working on a web application where I need to schedule some code.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.