-3

What is the difference between delete and free in C++ and which one is called by the C++'s default destructor?

kivk02
  • 599
  • 1
  • 4
  • 16
  • 2
    Find answer here: http://stackoverflow.com/questions/240212/what-is-the-difference-between-new-delete-and-malloc-free – Laura Maftei Oct 18 '14 at 19:55

1 Answers1

0

A constructor is used to initialize a data type. A destructor is used to clean up after the data type leaves scope or is deleted. Neither cares if the instance is automatic or otherwise.

New and delete are keywords that allocate space for a data type on the free store and call the constructor to initialize it (or the destructor to clean it up).

Malloc and free are C language functions that manage the heap. The free store for most types is implemented with the heap--in other words new/delete often result in calls to malloc and free.

Edward Strange
  • 40,307
  • 7
  • 73
  • 125