Skip to main content
destructor

destructor

1 8.1
A special function in a program that frees an object's memory or a machine that breaks things
  • noun
  • /dɪˈstrʌktər/
  • Specialized
translation icon : destructor
  • When an object is no longer needed, its destructor is invoked to free the allocated memory.

Examples

  • OK, so the destructor gets called in the most.

  • The main idea is to leverage the existing work done for the copy constructor and the destructor.

    Blog text (18)
  • I don't think in my test code any objects have reached the point where they would call their destructor yet.

    Blog text (18)
  • From what I see of your code, you need a proper destructor in your smart pointer class to call release and fix the counter.

    Blog text (18)
  • I have yet to implement the destructors, but I think I am having issues aside from that right now.

    Blog text (18)
  • I added destructor as you suggested, and interestingly, it is called during the bp2 = new B line of code.

    Blog text (18)
  • They also call the object constructor and destructor, and the C functions don't do that.

  • I thought the new returns a raw pointer of type U, but my Sptr's destructor is called? -- Incyc 2 days ago

    Blog text (18)
  • Note that this approach also works if the right-hand side isn't T, i.e., you can still leverage a corresponding constructor, the destructor, and swap().

    Blog text (18)
  • In C++ programming, the destructor is automatically called when an object goes out of scope.

Compounds

Mayetiola destructor
  • Specialized
9.9

A small fly whose young eat wheat plants and damage crops

9.9

A fungus that infects onion plants and causes grey fuzzy leaves

Surface Forms

destructor singular
destructors plural

Morphology

destructor = destruct (semi-transparent) = destruct + or

Morphologically an agentive noun formed from 'destruct', but the programming sense is a domain-specific technical meaning (a function that destroys an object) rather than a prototypical person/thing that destroys.

Etymology

Destructor comes from the parts de- ('down' or 'away') and struct ('build'), like in structure. In programming, a destructor is a special function that 'takes apart' an object or frees its memory and resources when the object is no longer needed, so the name keeps the idea of 'undoing a build' or breaking something down.