Re: Garbage Collection - The Trash Begins To Pile Up
James Kanze wrote:
Mirek Fidler wrote:
James Kanze wrote:
Le Chaud Lapin wrote:
In GUI based client software, the situation (except for eternal
life) is similar for the GUI objects: a window is created as a
response to some GUI input, and is destroyed later as a response
to a different GUI input.
I am not sure about your other example, but I am pretty sure that in
GUI world, situation is almost completely deterministic.
I'm very sure it's deterministic. Chaud Lapin said that he
never used dynamically allocated objects, however, and I can't
quite see how you could get such objects to correspond to the
lifetime of local variables.
I do, just not all the time (perhaps 1% of the time). Here is some
code (with x's for function names to conserve intellectual property) of
where I am using naked news:
// Start primary engine threads:
thread_stack.acquire();
thread_stack.push (new Thread::Object(&xxxxxx_xxxxxxx));
thread_stack.push (new Thread::Object(&xxxx_xxxxxxx));
thread_stack.push (new Thread::Object(&xxxxxx_xxxxx);
thread_stack.push (new Thread::Object(&xxxxxx_xxxxxxx));
thread_stack.push (new Thread::Object(&xxxx_xxxxxxx));
thread_stack.push (new Thread::Object(&xxxxxx_xxxxxxx));
thread_stack.push (new Thread::Object(&xxxx_xxxxxx));
thread_stack.push (new Thread::Object(&xxxxxx_xxxxxxx));
thread_stack.push (new Thread::Object(&xxxxx_xxxxxxxxxxxx));
thread_stack.push (new Thread::Object(&xxxxxx_xxxx));
thread_stack.push (new Thread::Object(&xxxx_xxxxxxx));
thread_stack.push (new Thread::Object(&xxx_xxxxxxxxxx));
thread_stack.release();
Here are the corresponding naked deletes:
// Stop all engine threads:
thread_stack.acquire();
while (!thread_stack.is_empty())
{
delete thread_stack.top();
thread_stack.pop();
}
thread_stack.release();
This is one of the few situations where I discovered (under my model)
that there was no choice.
A friend of mine and I had toyed around with making a GUI system that
was based entirely on C++, but with a distributed aspect, much like X.
We never got around to doing it, but in that case, the GUI elements on
the screen would be at global scope, so the lifetime would be "forever"
until it is time to go away.
Note that there is nothing inherently wrong with maintaining a global
container that contains the objects themselves instead of pointers to
those objects, so you could still avoid explicit calls of new and
delete.
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]