Ask a questionAsk a question
 

AnswerShallow copy & deep copy

Answers

  • Sunday, June 15, 2008 11:58 AMLasse V. Karlsen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Simplified explanation follows:

    As an example, you have an object containing references to other objects.

    For instance, a Person object, containing references to an Address object, several Phone objects, etc.

    If you make a shallow copy of that Person object you now have two Person objects, but they share the Address objects and Phone objects. In other words, you only make a new Person object, and then link it up to the existing Address and Phone objects.

    A deep copy, on the other hand, will make new copies of everything, so that both Person objects now have their own set of Address and Phone objects.

    http://presentationmode.blogspot.com/
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

All Replies

  • Sunday, June 15, 2008 11:58 AMLasse V. Karlsen Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Simplified explanation follows:

    As an example, you have an object containing references to other objects.

    For instance, a Person object, containing references to an Address object, several Phone objects, etc.

    If you make a shallow copy of that Person object you now have two Person objects, but they share the Address objects and Phone objects. In other words, you only make a new Person object, and then link it up to the existing Address and Phone objects.

    A deep copy, on the other hand, will make new copies of everything, so that both Person objects now have their own set of Address and Phone objects.

    http://presentationmode.blogspot.com/
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.