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 7184347
In Process

The Archive Base Latest Questions

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

Possible Duplicate: Setting Objects to Null/Nothing after use in .NET Do you need to

  • 0

Possible Duplicate:
Setting Objects to Null/Nothing after use in .NET
Do you need to dispose of objects and set them to null?

For large, or high traffic website:

First question:

Will set Object=null (not Disposable ) release memory?
Or is other way to release memory?

Second question:

Is explicitly release memory as above necessary in normal code?

  • 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. Editorial Team
    Editorial Team
    2026-05-28T18:11:00+00:00Added an answer on May 28, 2026 at 6:11 pm

    No, it won’t do it immediately, and no, it’s usually unnecessary if you’re writing your code the right way.

    If you have a resource that implements IDisposable, call Dispose() on it, or even better, put it in a using(...) block – it’s much faster and will release the proper resources. If you have several large objects in the same scope that aren’t COM objects or don’t implement some form of disposal mechanism, doing:

    someObject = null;
    GC.Collect();
    

    might help, but you’re probably better off restructuring your code so you don’t end up in that situation.

    If you’re doing this before objects go out of scope, it’s completely superfluous and makes things worse. More so if you set things to null in your finalizer. For example, never do this:

    public void aFunction() {
        SomeThing anObject = new SomeThing();
        // ...
        anObject = null;
    }
    

    nor this:

    public ~MyClass() {
        this.Something = null; // WRONG!
        this.SomethingElse.Dispose(); // DANGEROUS!
        this.SomeObject.Notify("I got finalized!"); // ALSO DANGEROUS!
    }
    

    And, for the sake of completeness, you do this:

    Marshal.ReleaseComObject(someObj);
    

    to release a COM object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Any sense to set obj = null(Nothing) in Dispose()? I understand if
Possible Duplicate: Setting variable to NULL after free … I am learning about good
Possible Duplicate: Why is it an error to use an empty set of brackets
Possible Duplicate: Is it worth setting pointers to NULL in a destructor? Do I
Possible Duplicate: In PHP, what is the differences between NULL and setting a string
Possible Duplicate: Why setting to nil after releasing? Which of the following examples are
Possible Duplicate: Use autorelease when setting a retain property using dot syntax? What is
Possible Duplicate: Calling null on a class vs Dispose() Just want some information regarding
Possible Duplicate: C#: Public Fields versus Automatic Properties Do I need to use {
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should

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.