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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:06:59+00:00 2026-05-15T07:06:59+00:00

The question I have might be more to do with semantics than with the

  • 0

The question I have might be more to do with semantics than with the actual use of IDisposable. I am working on implementing a singleton class that is in charge of managing a database instance that is created during the execution of the application. When the application closes this database should be deleted.

Right now I have this delete being handled by a Cleanup() method of the singleton that the application calls when it is closing. As I was writing the documentation for Cleanup() it struck me that I was describing what a Dispose() method should be used for i.e. cleaning up resources. I had originally not implemented IDisposable because it seemed out of place in my singleton, because I didn’t want anything to dispose the singleton itself. There isn’t currently, but in the future might be a reason that this Cleanup() might be called but the singleton should will need to still exist. I think I can include GC.SuppressFinalize(this); in the Dispose method to make this feasible.

My question therefore is multi-parted:

1) Is implementing IDisposable on a singleton fundamentally a bad idea?

2) Am I just mixing semantics here by having a Cleanup() instead of a Dispose() and since I’m disposing resources I really should use a dispose?

3) Will implementing ‘Dispose()’ with GC.SuppressFinalize(this); make it so my singleton is not actually destroyed in the case I want it to live after a call to clean-up the database.

  • 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-15T07:07:00+00:00Added an answer on May 15, 2026 at 7:07 am

    In short, if you have a singleton and you call dispose. Any time that any object tries to use it after that, will be using an object in a disposed state.

    Now putting it in, and disposing of the object after the application is done with it, isn’t necessarily bad. You do have to be careful though when you call it. If you are really concerned with the cleanup and you have only one reference to it, you can put the clean up code in the objects finalizer ~YourClass that way it will only be called with .Net is sure it is no longer needed (when the application closes, if it is a true singleton).

    Am I just mixing semantics here by
    having a Cleanup() instead of a
    Dispose() and since I’m disposing
    resources I really should use a
    dispose?

    Yes, this is just semantics. Dispose is the standard for showing there are things that need to be cleared up after the program is done with the object.

    Will implementing ‘Dispose()’ with
    GC.SuppressFinalize(this); make it so
    my singleton is not actually destroyed
    in the case I want it to live after a
    call to clean-up the database.

    No what this means is that when you call the dispose method, the Garbage Collector won’t call the object’s custom finalizer.

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

Sidebar

Related Questions

OK. This might be more of a math question but here goes. I have
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
The question might seem a bit confusing but I have an if statement that
I have a noob-question, that might be similar to Dynamically create multiple instances of
I have a question which might be more general, but I came across it
I know that this question might have been asked like 100 times, but, believe
I believe this question might have been previously attempted in 2006 on a different
I know this question might have already been discussed a thousands of times but
I might have pretty basic question about regex. I have the following regex, which
I asked a question , title of which might have been misleading so I'm

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.