469,580 Members | 1,992 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,580 developers. It's quick & easy.

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++.moderated. First time posters: Do this! ]
Jul 19 '05 #1
3 1790
[dropped moderated]
"joe martin" <no@never.com> wrote in message
news:4m********************************@4ax.com...
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++.moderated. First time posters: Do

this! ]

http://www.parashift.com/c++-faq-lit...html#faq-10.13 ,
or around there.
--
Best Regards, John E.
Jul 19 '05 #2
In article <4m********************************@4ax.com>,
on 12 Jul 2003 09:16:40 -0400,
joe martin <no@never.com> wrote:
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.


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++.moderated. First time posters: Do this! ]
Jul 19 '05 #3
In message <4m********************************@4ax.com>, joe martin
<no@never.com> writes
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.


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++.moderated. First time posters: Do this! ]
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Rajesh Garg | last post: by
3 posts views Thread by Nuno Barros | last post: by
10 posts views Thread by amparikh | last post: by
26 posts views Thread by Michi Henning | last post: by
8 posts views Thread by Edward Diener | last post: by
7 posts views Thread by Christian Christmann | last post: by
5 posts views Thread by Bushido Hacks | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.