answersLogoWhite

0


Best Answer

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.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What does the delete operator do in addition to deallocation of memory space?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Do you need to deallocate memory when an object is not in use?

Be more specific with your question:Java: deallocation is always automaticC++: objects allocated with new have to be released with delete


What is the memory management operator in c plus plus?

There is no memory management operator in C++ -- it is an unmanaged language. You use the C++ new operator to allocate memory, and use the C++ delete operator to release previously allocated memory.


How can delete operator used to prevent memory leak?

ss


Which operator is used for deallocating memory in c plus plus?

delete


What are problem that can be arise when using allocating memory dynamic memory?

1. Using memory before/after the allocated area.2. Using the memory after deallocation.3. Forgetting deallocation.4. Multiple deallocation.5. Non-checking whether the allocation was succesfull or not.Not releasing dynamically allocated memory when it is no longer needed can cause the system to run out of mmory prematurely .this sometimes called a"memory leak"


What will effect if an operating system cannot perform memory deallocation?

/


Why use new and delete operator overloading in c plus plus?

one reason to use new and delete operator overloading in c++ is when you are using your own memory manager code. when the user of your code calls the new keywork, your memory manager code can allocate memory.


Explain the purpose of new and delete operator?

The new operator instantiates a named object of a given type while the delete operator destroys an object. The new operator invokes the object's default constructor unless directed to invoke a specific constructor. The delete operator always invokes the object's destructor.


Can memory which has been allocated by new be freed by free?

No, you have to use the operator delete to objects created by new.


What function is used to release the memory on heap?

The free() function releases memory obtained with the malloc() family of functions. The delete and delete [] operators release memory obtained with the new operator. Note: realloc() can allocate and free memories as well as reallocate.


Delete memory release operator in c plus plus?

You can't physically delete memory, you can only delete a pointer to allocated memory, which subsequently releases the memory back to the system. The operator is delete, passing the pointer as the operand. If the pointer points to an array, then you must also use the index operator [] in front of the pointer name.int main(){// pointer to an int type with value 100int* ptr_int = new int(100);// ... use pointer ...// release the integerdelete ptr_int;// pointer to an array 100 int types (with undefined values)int* ptr_int_array = new int[100];// ... use array ...// release the arraydelete [] ptr_int_array;return(0);}


How do you delete variables that are dynamically allocated?

It depends, especially if you are going to use C++.If you allocated the variable using the malloc call or any of its derivatives you must use the corresponding 'free' subroutine call to delete them.If you use the more modern C++ 'new' operator, then use the 'delete' operator to remove the memory dynamically in the program.