Is deleting a pointer same as freeing a pointer (that allocates the memory)?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Deleting a pointer (or deleting what it points to, alternatively) means
pwas allocated prior to that statement likeIt may also refer to using other ways of dynamic memory management, like
freewhich was previously allocated using
mallocorcallocThe latter is more often referred to as "freeing", while the former is more often called "deleting".
deleteis used for classes with a destructor sincedeletewill call the destructor in addition to freeing the memory.free(andmalloc,callocetc) is used for basic types, but in C++newanddeletecan be used for them likewise, so there isn’t much reason to usemallocin C++, except for compatibility reasons.