answersLogoWhite

0

I agree with @Hilmar. You can never predict when exactly the object will be destroyed. But, you can definitely predict when an object is ready to be destroyed.

Difference between the two can be easily explained using an example (I'm using JAVA here):

Employee emp = new Employee("Dexter");

This statement creates an object of Employee (with name Dexter) which resides in the heap.

As long as you are using the reference "emp" for this object , the object will stay there. Its indestructible. Garbage Collector cannot even touch it.

Now lets say, after a few lines of code, you are executing:

emp = new Employee("RITA");

This creates a new object of Employee (with name RITA), but notice that the reference "emp" no longer points to our old object with the name Dexter. Hence the object of Employee with the name Dexter has no references associated with it.

And this makes it eligible for the Garbage Collection, and whenever the next round of Garbage Collection happens, the mighty GarbageCollector will not leave this chance to eat up the Employee (with the name Dexter).

User Avatar

Wiki User

9y ago

What else can I help you with?

Continue Learning about Engineering

What is an essential of Object Oriented Programming?

The 3 essential concepts of Object Oriented Programming are:InheritanceEncapsulation &Polymorphism


What is object based programming language?

Object-based programming language is a language that supports all the features of object oriented programming features like classes,object,encapsulation ,abstraction,polymorphism etc except inheritence.


Full form of oops?

The full form of OOP is Object-Oriented Programming.


What actually mean by object oriented programming Is C plus plus is a object oriented programming?

Just eat a watermellon!


Can we create an array of objects for a class having default constructor Justify your answer?

See example code below. #include <iostream> class x { private: // Members. static int counter; int data; public: // Default constructor and destructor. x():data(++counter){printf("Object %d created!\n",data);} ~x(){printf("Object %d destroyed!\n",data);} // other members omitted for brevity... }; // Initialise static counter. int x::counter=0; int main() { // Instantiate an array of 10 objects. x arr[10]; // .. do some work with the array .. return( 0 ); // The array falls from scope, destroying the objects. } Example output: Object 1 created! Object 2 created! Object 3 created! Object 4 created! Object 5 created! Object 6 created! Object 7 created! Object 8 created! Object 9 created! Object 10 created! Object 10 destroyed! Object 9 destroyed! Object 8 destroyed! Object 7 destroyed! Object 6 destroyed! Object 5 destroyed! Object 4 destroyed! Object 3 destroyed! Object 2 destroyed! Object 1 destroyed!

Related Questions

When was Object to Be Destroyed created?

Object to Be Destroyed was created in 1923.


What is full form of oop's?

Object Oriented Programming


Can an indestructible object be destroyed or killed?

No, an indestructible object cannot be destroyed or killed.


Is PHP object oriented?

Yes - 'advanced' PHP programming uses Object Oriented Programming (OOP).


What is an essential of Object Oriented Programming?

The 3 essential concepts of Object Oriented Programming are:InheritanceEncapsulation &Polymorphism


What is object based programming language?

Object-based programming language is a language that supports all the features of object oriented programming features like classes,object,encapsulation ,abstraction,polymorphism etc except inheritence.


Full form of oops?

The full form of OOP is Object-Oriented Programming.


What actually mean by object oriented programming Is C plus plus is a object oriented programming?

Just eat a watermellon!


Difference between conventional programming and object oriented programming?

diff between oops and conventional programming


What is copy constructor in object oriented programming?

The purpose of constructor in object oriented programming is to initialize data. Likewise copy constructors are used to initialize an object with data from another object.


What is the structure of the ots keyword in the programming language you are using?

In the programming language I am using, the structure of the "ots" keyword is typically used for object-oriented programming and stands for "object to string." It is used to convert an object into a string representation.


Can we create an array of objects for a class having default constructor Justify your answer?

See example code below. #include <iostream> class x { private: // Members. static int counter; int data; public: // Default constructor and destructor. x():data(++counter){printf("Object %d created!\n",data);} ~x(){printf("Object %d destroyed!\n",data);} // other members omitted for brevity... }; // Initialise static counter. int x::counter=0; int main() { // Instantiate an array of 10 objects. x arr[10]; // .. do some work with the array .. return( 0 ); // The array falls from scope, destroying the objects. } Example output: Object 1 created! Object 2 created! Object 3 created! Object 4 created! Object 5 created! Object 6 created! Object 7 created! Object 8 created! Object 9 created! Object 10 created! Object 10 destroyed! Object 9 destroyed! Object 8 destroyed! Object 7 destroyed! Object 6 destroyed! Object 5 destroyed! Object 4 destroyed! Object 3 destroyed! Object 2 destroyed! Object 1 destroyed!