Question In a class, there is a reference or pointer of an
object of
another class embedded, and the memory is either allocated
or assigned to the new object created for this class. In
the constructor, parameters are passed to initialize the
data members and the embedded object reference to get
inialized. What measures or design change should be advised
for proper destruction and avioding memory leaks, getting
pointers dangling for the embedded object memory
allocation? Please suggest.
Question Submitted By :: Sunil Kumar
I also faced this Question!! Rank Answer Posted By
Re: In a class, there is a reference or pointer of an
object of another class embedded, and the memory is either
allocated or assigned to the new object created for this
class. In the constructor, parameters are passed to
initialize the data members and the embedded object
reference to get inialized. What measures or design change
should be advised for proper destruction and avioding
memory leaks, getting pointers dangling for the embedded
object memory allocation? Please suggest.
Answer
# 1 use copy constructors
0 Shanthila
There is something to be taken care in destructor, in copy
constructor, suppose the memory is assigned to the embedded
member object pointer with the parameter passed value, but
if some other objects of different class also are pointing
to this memory, then if some one deletes the object then
this class member pointer object will become dangling, or
if the object is not deleted properly then there will be
memory leak. Please suggest the design change required to
handle or avoid this situation
No Answer is Posted For this Question
Be the First to Post Answer
why the memory allocated with new cant be freed using free()
What is namespace?
what is main difference between object oriented object base
How to call a non virtual function in the derived class by using base class pointer
different types of castings
what is an qt4 interface?
design class for linked list and include constructor,destructor,insert option. node of form struct node { int data; struct node &ptr; }
What are oops methods?
Why u change company?
difference between static and non-static variables?
How to calculate the age from the date of birth by using the program?
What is encapsulation in simple terms?