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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:18:01+00:00 2026-06-09T23:18:01+00:00

We’ve inherited large legacy application which is structured roughly like this: class Application {

  • 0

We’ve inherited large legacy application which is structured roughly like this:

class Application
{
    Foo* m_foo;
    Bar* m_bar;
    Baz* m_baz;

public:

    Foo* getFoo() { return m_foo; }
    Bar* getBar() { return m_bar; }
    Baz* getBaz() { return m_baz; }

    void Init()
    {
        m_foo = new Foo();
        m_bar = new Bar();
        m_baz = new Baz();

        // all of them are singletons, which can call each other
        // whenever they please
        // may have internal threads, open files, acquire
        // network resources, etc.
        SomeManager.Init(this);
        SomeOtherManager.Init(this);
        AnotherManager.Init(this);
        SomeManagerWrapper.Init(this);
        ManagerWrapperHelper.Init(this);
    }

    void Work()
    {
        SomeManagerWrapperHelperWhateverController.Start();

        // it will never finish
    }

    // no destructor, no cleanup
};

All managers once created stay there for the whole application lifetime. The application does not have close or shutdown methods and managers also doesn’t have those. So, the complex inter dependencies are never dealt with.

The question is: if the objects lifetime is tightly coupled with the application lifetime, is it accepted practice to not have cleanup at all? Will the operating system (Windows in our case) be able to cleanup everything (kill threads, close open file handles, sockets, etc.) once the process ends (by ending it in task manager or by calling special functions like ExitProcess, Abort, etc.)? What are possible problems with the above approach?

Or more generic question: are destructors absolutely necessary for global objects (declared outside of main)?

  • 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-06-09T23:18:01+00:00Added an answer on June 9, 2026 at 11:18 pm

    Will the operating system (Windows in our case) be able to cleanup
    everything (kill threads, close open file handles, sockets, etc.) once
    the process ends (by ending it in task manager or by calling special
    functions like ExitProcess, Abort, etc.)? What are possible problems
    with the above approach?

    As long as your objects aren’t initialising any resources not cleaned up by the operating system, then it doesn’t make any practical difference whether you explicitly clean up or not, as the OS will mop up for you when your process is terminated.

    However, if your objects are creating resources which are not cleaned up by the OS then you’ve got a problem and need a destructor or some other explicit clean up code somewhere in your app.

    Consider if one of those objects creates sessions on some remote service, like a database for example. Of course, the OS doesn’t magically know that this has been done or how to clean them up when your process dies, so those sessions would remain open until something kills them (the DBMS itself probably, by enforcing some timeout threshold or other). Perhaps not a problem if your app is a tiny user of resources and you’re running on a big infrastructure – but if your app creates and then orphans enough sessions then that resource contention on that remote service might start to become a problem.

    if the objects lifetime is tightly coupled with the application
    lifetime, is it accepted practice to not have cleanup at all?

    That’s a matter of subjective debate. My personal preference is to include the explicit cleanup code and make each object I create personally responsible for cleaning up after itself wherever practical. If application-lifetime objects are ever refactored such that they no longer live for the lifetime of the object, I don’t have to go back and figure out whether I need to add previously-omitted cleanup. I guess for cleanup I’m saying that I generally prefer to lean towards RAII over the more pragmatic YAGNI.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.