Questions tagged [destruction]
75 questions
60
votes
9 answers
Destruction order of static objects in C++
Can I control the order static objects are being destructed?
Is there any way to enforce my desired order? For example to specify in some way that I would like a certain object to be destroyed last, or at least after another static object?

Gal Goldman
- 8,641
- 11
- 45
- 45
23
votes
2 answers
How does Qt delete objects ? And what is the best way to store QObjects?
I heard that objects in Qt will automatically delete their children, I want to know what will happen in those situations.
#include
#include
#include
#include
int main(int argc, char **argv)
{
…

Linlix
- 377
- 1
- 2
- 9
15
votes
3 answers
Late destruction of function parameters
According to 5.2.2/4 "Function call" in n4640 (8.2.2/4 in n4659) function parameters are created and destroyed in the context of the caller. And implementations are allowed to delay the destruction of function parameters to the end of the enclosing…

AnT stands with Russia
- 312,472
- 42
- 525
- 765
13
votes
3 answers
Clojure applying a map and keyword arguments destruction
Consider a function with the following signature:
(defn make-widget [& {:keys [x y] :or {x 10 y 20}}]
...)
What is the best way to pass a map to the function, e.g.:
(make-widget {:x 100})
or
(make-widget {:y 200 :x 0})
What I have currently…

Zaur Nasibov
- 22,280
- 12
- 56
- 83
12
votes
2 answers
Would it be reasonable to define destruction order of vector elements?
I know that vector elements destruction order is not defined by C++ standard (see Order of destruction of elements of an std::vector) and I saw that all compilers I checked do this destruction from begin to end - which is quite surprising to me…

PiotrNycz
- 23,099
- 7
- 66
- 112
10
votes
2 answers
Does the vptr change during destruction?
I was looking at this article, and it says "Upon entry to the base class destructor, the object becomes a base class object, and all parts of C++—virtual functions, dynamic_casts, etc.—treat it that way." Does this mean that the vptr has changed…

pythonic metaphor
- 10,296
- 18
- 68
- 110
10
votes
2 answers
Shouldn't the temporary A(3) be destroyed before "Here" is printed?
Shouldn't the temporary A(3) be destroyed before "Here" gets printed?
#include
struct A
{
int a;
A() { std::cout << "A()" << std::endl; }
A(int a) : a(a) { std::cout << "A(" << a << ")" << std::endl; }
~A() { std::cout <<…

François-Marie Arouet
- 667
- 5
- 11
8
votes
1 answer
Array destruction and unused vars marked by eslint
I have code like this in my code:
let [a, b, c, d, e] = await component.getState.call(game.gameId);
Variables b, c, e used below in code but not a and d. In the same time I have eslint check that marks unused variables.
Is there any way to write…

Alex G.P.
- 9,609
- 6
- 46
- 81
8
votes
1 answer
Spring Custom Scope Lifecycle Bean Termination
Question: How can I tell Spring that a set of beans with a custom scope should all be considered garbage, so that the next request on the same thread would not re-use their state?
What I've done: I've implemented a custom scope in Spring, to mimic…

Andrew Cotton
- 415
- 3
- 12
6
votes
4 answers
Correct way to destroy a form and show another in Delphi
Currently in my program I have a Startup form, and a Main form. The startup form shows for a second or two.
Right now, I have the following code within a timer:
frmStartup.Destroy;
frmMain := TfrmMain.Create(Self);
frmMain.Show;
Right now,…

James
- 133
- 2
- 3
- 9
5
votes
2 answers
What is the difference between `__del__` and `__delete__`?
Suppose someone didn't know what the difference was between __del__ and __delete__? Write an explanation.

Toothpick Anemone
- 4,290
- 2
- 20
- 42
5
votes
4 answers
Local variables construction and destruction with optimizer involved
If I have this code:
class A { ... };
class B { ... };
void dummy()
{
A a(...);
B b(...);
...
}
I know that variables a and b will be destroyed in reverse allocation order (b will be destroyed first, then a); but can I be sure that the…

Loghorn
- 2,729
- 17
- 22
5
votes
3 answers
Behaviour of explicit call to destructor
The definition of some_class is:
class some_class
{
// stuff
public:
~some_class()
{
delete dynamic_three;
}
private:
classA one;
classB two;
classC* dynamic_three;
}
When the lifetime of a object ends, its…

ABu
- 10,423
- 6
- 52
- 103
4
votes
6 answers
Is there a guarantee on the order in which the Dispose() method is called when using multiple using statements for the same scope in C#?
using (Stuff1 stf1 = new Stuff1(...)) // Allocation of stf1
using (Stuff2 stf2 = new Stuff2(...)) // Allocation of stf2
{
try
{
// ... do stuff with stf1 and stf2 here ...
}
catch (Stuff1Exception ex1)
{
// ...
…

user972301
- 137
- 8
4
votes
3 answers
Automatic object destruction
Is the destruction of automatic objects (objects created on the stack) guaranteed to be executed not before they go out of scope?
To clarify:
#include
class A {
public:
A() {
std::cout << "1";
}
~A() {
std::cout…

bitmask
- 32,434
- 14
- 99
- 159