Questions tagged [destruction]

75 questions
4
votes
1 answer

Destruction order of the main thread and the use of pthread_key_create

I was wondering about the use of pthread_key_create while passing in a destructor function. I wanted to have something like this: static ComplexObject foo; void workoncomplex(void *) { foo.dosomestuff(); } static pthread_key_t…
Salgar
  • 7,687
  • 1
  • 25
  • 39
4
votes
1 answer

building a vector to allow uninitialized storage

Let's say I want to build a vector container that, unlike std::vector, allows uninitialized storage. The usage of the container, say vec , would be roughly like this: User explicitly states the vector should allocate N uninitialized elements…
iavr
  • 7,547
  • 1
  • 18
  • 53
3
votes
1 answer

Spark SkinnableComponent skinDestructionPolicy

As a part of trying to tackle a memory leak in our application, we discovered that for every SkinnableComponent, the skinDestructionPolicy is set to "never" by default. This means that when using static skin parts, the skin is forever detained in…
Dennis Jaamann
  • 3,547
  • 2
  • 23
  • 42
3
votes
1 answer

thread_local static class is destroyed at invalid address on program exit

I have an issue with the destruction of a thread_local static object. #include #include struct UsesLoc { UsesLoc() { loc.counter++; } struct Loc { Loc() { std::cout << "I am at " <<…
3
votes
2 answers

Is there a counterpart to "CreateInstance"?

We have some code that uses MSXML, and does this to create the XML document object: MSXML2::IXMLDOMDocumentPtr doc_in; doc_in.CreateInstance("Msxml2.DOMDocument.6.0"); Once we're finished with doc_in, how do we destroy it? Is it just…
Colen
  • 13,428
  • 21
  • 78
  • 107
3
votes
4 answers

Exception free tree destruction in C++

I have recently managed to get a stack overflow when destroying a tree by deleting its root 'Node', while the Node destructor is similar to this: Node::~Node(){ for(int i=0;i
Juraj Blaho
  • 13,301
  • 7
  • 50
  • 96
3
votes
5 answers

Question about exact time of destruction of temporaries in C++

is the following code safe (it works in DEBUG) : void takesPointer(const Type* v);//this function does read from v, it doesn't alter v in any way Type getValue(); ... takesPointer(&getValue());//gives warning while compiling "not an lvalue" ... Type…
J.Colmsee
  • 41
  • 2
2
votes
0 answers

Execution order of global variable destructor and gcc attribute__((destructor))

This is a GCC specific issue. I'm encountering a werid issue in a .so library. The demo code of this .so library could be: __attribute__((init_priority(101))) std::unique_ptr global_object; __attribute__((constructor)) void…
xnervwang
  • 125
  • 1
  • 8
2
votes
0 answers

Is there a way to tell if a C++ application is exiting?

I have some code that is in a c++ destructor, but I want it to do something different than normal if it is being destructed due to application exiting as opposed to a regular destruction. Is there a way to do this? More info: I have a logger object…
csm10495
  • 569
  • 6
  • 12
2
votes
3 answers

How does vector not destroy element twice after reducing its size?

For testing purposes, I was trying to create my own vector class, and I couldn't figure out how std::vector size reduction works. class A { A() { std::cout << "A constructed") << std::endl; } ~A() { std::cout << "A destroyed") <<…
user7769147
  • 1,559
  • 9
  • 15
2
votes
1 answer

Segmentation fault when trying to destroy sf::Font

I am working with the SFML package and receive a segmentation fault when trying to close the window/program. I have located the line in my code that results in segmentation fault, which is when I try to destroy the sf::Font used for drawing text in…
2
votes
2 answers

How to enforce that a given resource will always be removed first?

In my project I have a system of events. You can connect a callback to an event and any time the event is sent, your callback(s) is called. Upon connecting to an event you get a token. As long as the token is not destroyed, the connection is…
Marcin K.
  • 683
  • 1
  • 9
  • 20
2
votes
1 answer

Undefined behavior during destrction?

Let's consider the following code: #include struct A{ virtual void foo(){ } }; struct B : A { virtual void foo(){ } }; A *a = new B; int main() { delete a; //UB? } I deliberately didn't define a virtual destructor. The compiler…
user2953119
2
votes
1 answer

What could cause the destructor of a parent to be called during construction of the child?

enter code hereI am seeing segfaults in a strange part of my code, and after using valgrind, it seemed the problem was the destructor of a parent being called during construction of the child. This is strange, so fired up gdb and indeed, I see…
pythonic metaphor
  • 10,296
  • 18
  • 68
  • 110
2
votes
3 answers

Destructor not invoked when deleting void pointer

I've got 3 classes class A { A(); virtual ~A(); } class B : public A { B(); ~B(); } class C { void *obj; C() : obj(nullptr) {} ~C() { if (obj) delete obj; } } when I use class C as a container for any child of class A…
EOG
  • 1,677
  • 2
  • 22
  • 36