Does it actually work on some compilers/machines but on others it causes heap corruptions and crashes?
Does anyone have any insight into what going on under the covers?
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.
C++ wants to call a destructor on the object when you use
delete, but passing it tofreedoesn’t allow this to happen. If the object contained other objects then those objects’ destructors would not be called either. If the object had pointers in it then those wouldn’t get freed.Additionally C++’s
newanddeletecould actually request a larger amount of memory frommallocand use the extra for book keeping (like storing the address of the destructor function), and so the pointer you passed tofreewould not actually be one that wasmalloced.