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

  • SEARCH
  • Home
  • 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 61479
In Process

The Archive Base Latest Questions

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

This is something that I have never fully grasped in .NET as to the

  • 0

This is something that I have never fully grasped in .NET as to the correct application of the .dispose() method.

Say I have something like

Public Class someClass()   sub someMethod     ' do some stuff tying up resources   end sub End Class  public class mainApp    dim _class as new SomeClass   _class.someMethod() End Class 

In all cases is it good practice to implement a dispose method, and if so what should go in there?

If it is not the case that every class should have dispose method (which my gut feeling says the shouldn’t) what classes should? I have always thought anything which may tie up a resource (i.e. connection, datareader etc) should have a .dispose() which would unallocate these resources.

Also how would you enforce a calling into calling the .dispose() method?

  • 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:19:33+00:00Added an answer on May 10, 2026 at 6:19 pm

    I highly recommend reading Cleaning Up Unmanaged Resources on MSDN, it has articles touching on when to use Dispose and how to implement IDisposable correctly. Your gut instinct is mostly correct as you rarely have to implement IDisposable, unless your class uses unmanaged resources or is a container for an object that implements IDisposable.

    As to enforcing the calling of Dispose, when you properly implement the IDisposable interface you attach a finalizer which calls Dispose to catch those stragglers and deviant classes that forgot.

    Relevant articles:

    Implementing a Dispose Method

    Describes the implementation of the Dispose method for releasing unmanaged resources.

    Using Objects That Encapsulate Resources

    Describes ways to ensure that the Dispose method is called, such as the C# using statement (Using in Visual Basic).

    (edit: additional information added)

    In your example you have SomeClass.SomeMethod which does some work, presumably with a resource. If this resource isn’t a class member, you may be better served wrapping it in a using-statement, and forgetting about the devilish details of IDisposable.

    Public Class someClass()   sub someMethod     Using someResource As New ResourceType( arguments )        ' no worries about IDisposable for someResource, as it is automatic     End Using   end sub End Class 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
This is a C# console application. I have a function that does something like
This is something that I have always wondered about, but never bothered to profile.
Some existing web services I consume have methods that look something like this: List<Employee>
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
So I have a function that looks something like this: float function(){ float x
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
I have a table that looks something like this: word big expensive smart fast
I have a function that looks something like this: //iteration over scales foreach ($surveyScales
Before you answer this I have never developed anything popular enough to attain high

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.