What is the difference between the 'delete' and 'dispose' C++ operators with regards to dynamic memory allocation?
I'm assuming this is related to .NET managed C++ because standard C++ has no sense of "dispose".
Delete will release the memory used to store the object; this memory returns to the heap and can be used for other storage requirements.
Dispose will give the object the chance to release resources it acquired such as file handles, etc. Standard C++ would see this sort of task done in the destructor.
delete
will free memory dynamically allocated in unmanaged C++
Dispose
will force custom object implemented maintenance of disposable objects in managed C++/CLI
There's no dispose
operator (or standard function, or anything of that ilk) in standard C++ -- are you thinking of some specific proprietary framework, such as Microsoft's .NET "managed C++"? delete
is standard, it's indeed an operator, and must behave like this in any standard conforming implementation -- that's the main difference with operator dispose
, and also the main difference with operators unicorn
, toothfairy
, and santaclaus
, which have a lot in common since none of those exists!-) [[Sorry Virginia...!]]