answersLogoWhite

0


Best Answer

Delete is a built-in operator used forcibly release a dynamically allocated resource. Delete can only be used on pointer types, including pointer arrays.

A destructor is a class method used to clean up any resources acquired by objects of the class. Destructors are invoked automatically from the most-derived class to the least-derived class, as soon as an object falls from scope.

When you delete a pointer to an object, the object's destructor sequence is invoked. Note that you must not delete named objects otherwise you end up with a null reference. References must never be null.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

I'm presuming you mean the difference between delete and delete(). If not please clarify in the discussion section (punctuation is not permitted in questions).

There is no difference between delete and delete(). Delete is an operator implemented as a function so the operand (a dynamically allocated instance pointer) can be placed in parenthesis if desired, but is not required.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Delete is a C++ keyword that will de-allocate memory that was allocated using the "new" keyword. If delete is called on a class, the class will execute its destructor function before it is de-allocated. This is useful if your class allocated memory and needs to delete it before it is terminated. Otherwise a memory leak will occur.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

delete can be used only with primitive types and arrays based on the types. operator delete cannot be used for classes because problems with tracking and permissions. To free memory occupied with some class distructor was invented which is called automatically every time a variable defined in of class leaves its scope.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

You cannot call a destructor directly. They are called automatically when an object falls from scope.

delete is used in conjunction with the newoperator (similar to the way free is used in conjunction with malloc, calloc and realloc). When deleting an object instantiated with the new operator, the object's destructor is called automatically. Object references are deleted when they fall from scope (references can never be NULL while they are still in scope, and therefore cannot be deleted while in scope).

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

The destructor of a class is a method of the class that runs when the instance of class is about to be deleted. It does clean up that might be necessary, such as deallocating objects that were created on the heap. If the instance of the class represents a persistant object, such as a record in a database, the destructor is also responsible for deleting that record, depending on the class design.

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

We use the delete operator to release a memory resource that was previously allocated using the new operator.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between destructors and delete?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When is a destructor called?

Destructors are called when an object is no longer used. In a language like C++, this is done explicitly by the programmer when the delete operator is used on the object.


Does c language really supports destructors?

it doesnt support destructors


What is the Difference between virtual methods and non virtual methods in c sharp?

A function is a method that returns a value other than void. Methods includes functions, subroutines, constructors, destructors, and properties.


How do you describe the importance of destructors?

Destructors are used to free memory and release resources.


What does the delete operator do in addition to deallocation of memory space?

The delete operator calls the destructor of the object referenced by its operand. If the destructor is virtual, the destructor of each superclass up to the top of the inheritance hierarchy is also called, in order. If you don't define a destructor for a class, the compiler defines a default destructor that has no effect. Fundamental types (char, int, float, etc.) do not have destructors, so using delete has no other effects.As an aside: when you use inheritance, make sure to make your destructors virtual, so that objects are properly destroyed!Also note that you should not use C's free() on a pointer that you got from C++'s new, or use C++'s delete on a pointer you got from C's malloc(). These are not guaranteed to work, and mixing them might cause Big Bad Things to happen. In general, there is no reason to use malloc()/free() in C++ at all.

Related questions

Difference between format and delete?

What is the difference between delete and format?


What is the difference between delete and delete sheet command?

delete command would delete selected word,line, paragraph or even sheet. Whereas delete sheet command would delete the whole sheet


When is a destructor called?

Destructors are called when an object is no longer used. In a language like C++, this is done explicitly by the programmer when the delete operator is used on the object.


What is difference between delete file in DOS and delete file in Windows?

i don't know the difference but what i know is ... deleted file from MS-DOS is never go to the recycle bin. Thanks !


Difference between the delete key an the back space?

The backspace key deletes to the left of the cursor, and the delete key deletes to the right of the cursor.


When was The Destructors - band - created?

The Destructors - band - was created in 1977.


Does c language really supports destructors?

it doesnt support destructors


What is the Difference between virtual methods and non virtual methods in c sharp?

A function is a method that returns a value other than void. Methods includes functions, subroutines, constructors, destructors, and properties.


How do you describe the importance of destructors?

Destructors are used to free memory and release resources.


What is the difference between backspace and delete key?

The delete key removes the character above or to the right of the cursor. The backspace removes the character to the left of the cursor.


What are the ratings and certificates for The Destructors - 1968?

The Destructors - 1968 is rated/received certificates of: UK:A (original rating) (passed with cuts)


What is the difference between pressing the Delete key or the left arrow key in the middle of a line of text?

Delete key deletes any amount of text. The left arrow key only moves the I beam