destructors for statically declared objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • joe martin

    destructors for statically declared objects

    Does anyone know when or if destructors for statically declared
    objects are called? I am just wondering if I am leaking system
    resources each time i exit my program.

    Thanks,
    -Joe

    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.m oderated. First time posters: Do this! ]
  • John Ericson

    #2
    Re: destructors for statically declared objects

    [dropped moderated]
    "joe martin" <no@never.com > wrote in message
    news:4mhugv4d65 0jbf97k4rnt3fei 4rnuiss40@4ax.c om...[color=blue]
    > Does anyone know when or if destructors for statically[/color]
    declared[color=blue]
    > objects are called? I am just wondering if I am leaking[/color]
    system[color=blue]
    > resources each time i exit my program.
    >
    > Thanks,
    > -Joe
    >
    > [ See http://www.gotw.ca/resources/clcm.htm for info[/color]
    about ][color=blue]
    > [ comp.lang.c++.m oderated. First time posters: Do[/color]
    this! ]

    http://www.parashift.com/c++-faq-lit...html#faq-10.13 ,
    or around there.
    --
    Best Regards, John E.


    Comment

    • Andy Sawyer

      #3
      Re: destructors for statically declared objects

      In article <4mhugv4d650jbf 97k4rnt3fei4rnu iss40@4ax.com>,
      on 12 Jul 2003 09:16:40 -0400,
      joe martin <no@never.com > wrote:
      [color=blue]
      > Does anyone know when or if destructors for statically declared
      > objects are called? I am just wondering if I am leaking system
      > resources each time i exit my program.[/color]

      It depends on how you exit the program. If you call abort, then "no" is
      the answer. If you either call 'exit', or fall off the end of 'main'
      (which eventuall calls 'exit'), then the answer is "yes". If you
      terminate in any other fashion, then you're on your own...:)

      3.6.3p1 says:

      ,----
      | Destructors (12.4) for initialized objects of static storage duration
      | (declared at block scope or at namespace scope) are called as a result
      | of returning from main and as a result of calling exit (18.3). These
      | objects are destroyed in the reverse order of the completion of their
      | constructor or of the completion of their dynamic initialization. If an
      | object is initialized statically, the object is destroyed in the same
      | order as if the object was dynamically initialized. For an object of
      | array or class type, all subobjects of that object are destroyed before
      | any local object with static storage duration initialized during the
      | construction of the subobjects is destroyed.
      `----

      Regards,
      Andy S
      --
      "Light thinks it travels faster than anything but it is wrong. No matter
      how fast light travels it finds the darkness has always got there first,
      and is waiting for it." -- Terry Pratchett, Reaper Man

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.m oderated. First time posters: Do this! ]

      Comment

      • Francis Glassborow

        #4
        Re: destructors for statically declared objects

        In message <4mhugv4d650jbf 97k4rnt3fei4rnu iss40@4ax.com>, joe martin
        <no@never.com > writes[color=blue]
        >Does anyone know when or if destructors for statically declared
        >objects are called? I am just wondering if I am leaking system
        >resources each time i exit my program.[/color]

        They are called in the same way as atexit() registered functions are
        called and interleaved with those under the same rule (reverse of the
        order of initialisation/registration)


        --
        ACCU Spring Conference 2003 April 2-5
        The Conference you should not have missed
        ACCU Spring Conference 2004 Late April
        Francis Glassborow ACCU



        [ See http://www.gotw.ca/resources/clcm.htm for info about ]
        [ comp.lang.c++.m oderated. First time posters: Do this! ]

        Comment

        Working...