Shall we use 'free' to free memory assigned by new, What are
the further consequences??
Answers were Sorted based on User's Feedback
Answer / aruna kumar samal
yes you can use free to free memory assignrd by new but it
wo not call the destructor.
| Is This Answer Correct ? | 6 Yes | 0 No |
Answer / uma sankar pradhan
No,we shouldnot use 'free' to free memory assigned by new.
It causes memory leak and sometimes hanging of the system
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / nishikant sahu
Yes you can but not recommend, b'c some time when you class
hold the heap memory it can't be free by "Free" b'c of no
constructor call happening via "Free" and you get the memory
leak. so use New/ delete or malloc/free pair.
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / guest
Yes we can use free which was assigned by new.but in this
case no destrctor will be called as free doesn't call this.
So it is recommended that we should not use free if we
allcoate the memory using new.
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / krishnarao panchadi
Syntactically we can use "free" in place of "delete". But
semantically it is senseless as it wont call the destructor.
Note that, deallocating is not the only purpose of
using "delete". The destructor should also be called if you
call the constructor(while creating the object).
Failing to call "delete" may lead to system crash.
Using "free" wont call the desturctor.
| Is This Answer Correct ? | 2 Yes | 0 No |
How a new element can be added or pushed in a stack?
What do you mean by a template?
What is null pointer and void pointer?
What do you mean by translation unit?
Can you please explain the difference between using macro and inline functions?
What is the difference between "calloc" and "malloc"?
What is the use of c++ programming language in real life?
What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.
What is the default width for ouputting a long integer using the insertion operator?
If you push the numbers (in order) 1, 3, and 5 onto a stack, which pops out first a) 1 b) 5 c) 3
Which bitwise operator is used to check whether a particular bit is on or off?
What is the difference between the parameter to a template and the parameter to a function?