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 Posted / som shekhar

If you are using the reference orpointer of other class as
an Aggregation (class own every thing, tight coupling) then
the destructor should take care of it, but if the reference
or pointer is taken as composition (class doesnt owwn the
pointer, loose coupling) then the class destructor should
not worry about that.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Discuss the possibilities related to the termination of a program before entering the mainq method?

747


Why is polymorphism useful?

808


What is operator overloading in c++ example?

877


What is the meaning of string in c++?

805


Define a pointer to a data member of the type pointer to pointer?

778


How do we balance an AVL Tree in C++?

862


What is the rule of three?

778


Can you declare an array without a size in c++?

799


How does list r; differs from list r();?

916


How do you master coding?

826


When is the copy constructor called?

891


What are vectors used for in c++?

818


How can a called function determine the number of arguments that have been passed to it?

908


What is a far pointer? where we use it?

822


Is oops and c++ same?

799