Shall we use 'free' to free memory assigned by new, What are
the further consequences??

Answers were Sorted based on User's Feedback



Shall we use 'free' to free memory assigned by new, What are the further consequences??..

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

Shall we use 'free' to free memory assigned by new, What are the further consequences??..

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

Shall we use 'free' to free memory assigned by new, What are the further consequences??..

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

Shall we use 'free' to free memory assigned by new, What are the further consequences??..

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

Shall we use 'free' to free memory assigned by new, What are the further consequences??..

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

Post New Answer

More C++ General Interview Questions

What are the popular tools used to detect memory leaks in c++

4 Answers   TATA,


What is purpose of abstract class?

0 Answers  


an operation between an integer and real always yeilds a) integer result b) real result c) float result

0 Answers  


What is "mutable" keyword?

2 Answers   Infosys, Teradata,


What is the use of endl in c++ give an example?

0 Answers  






What is malloc in c++?

0 Answers  


What is function prototyping? What are its advantages?

0 Answers  


What happens when a function throws an exception that was not specified by an exception specification for this function?

1 Answers  


Write any small program that will compile in "C" but not in "C++"

10 Answers   Honeywell,


What is buffer and example?

0 Answers  


Can non graphic characters be used and processed in C++?

0 Answers   HCL,


Is it possible for the objects to read and write themselves?

0 Answers  


Categories