Re: Allocation during process exit
Christopher wrote:
On Apr 2, 12:35 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
Christopher wrote:
After all, how can I allocate a new global when the process is
trying to deallocate all globals?
Who said anything about allocating "a new global"? Dynamic storage
duration and static storage duration are not the same thing.
Its hard to say as I don't have access to the source causing the
problem, only my dependent source, but looking at the call stack it
appears as though:
1 the process has begun termination
2 global and statics have begun to be deallocated
3 some class in its deconstruction makes a call to a singleton's
GetInstance() method
4 the singleton, in turn, attempts to allocate itself using new and
its constructor,
5 new calls malloc
6 malloc calls _int_malloc
7 _int_ malloc calls _malloc_consolidate()
8 process hangs and never exits
Well... You see, '_int_malloc' or '_malloc_consolicate' are not C++
terms, they are implementation details. You could try finding out
more about those by contacting the creator of the standard library
you're using.
I use the word 'global' to describe the singleton, as its usually a
pointer or reference defined globally which points to or refers to
some memory on the heap.
Sounds like you need a better implementation of your singleton[s].
The class deconstrucing itself should attempt checking the validity
(existence) of the singletons and act accordingly. Try adding some
kind of "isOK" static member to your singleton, let it only set the
member after the instance is created and let it clear the member
when the singleton is destructed. Make a policy to never access
any objects after they've been destructed (that's UB, BTW). Make
sure the "some class" can actually behave acceptably without the
singleton that may have already been destructed.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask