Why is a destructor called when an object is created? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Why is a destructor called when an object is created?

11th Aug 2016, 12:57 PM
Sjardi Djoy Willems
Sjardi Djoy Willems - avatar
6 Answers
+ 4
When an object is created, a constructor is called, not a destructor. A destructor is called when an object is destroyed.
16th Aug 2016, 3:23 PM
Andrei Timofte
Andrei Timofte - avatar
+ 2
the object is destroyed at the end of the program.
12th Aug 2016, 1:33 PM
billy
+ 1
when an object is created the constructor gets called. the deconstructor instead is called when the garbage collector decide it or when you dispose of the object yourself
23rd Dec 2016, 11:19 PM
Victor
Victor - avatar
0
It's... not. It shouldn't be. Why, is there something wrong with a code you are working on?
30th Aug 2016, 5:09 PM
OBV10U3_NINJA
OBV10U3_NINJA - avatar
0
A constructor is called when object is created. A destructor is called when the execution of code is end & need to destroy the object.
4th Sep 2016, 8:01 PM
Nafis Zamáñ
Nafis Zamáñ - avatar
0
Don't know why I asked this, prob becouse something that was in de c# tutorial that was wierd for me
14th Jan 2017, 8:24 PM
Sjardi Djoy Willems
Sjardi Djoy Willems - avatar