Shallow copy and Deep Copy

Shallow copy

A shallow copy in progress.
A shallow copy having been completed.
A shallow copy in progress.

A shallow copy having been completed.
One method of copying an object is the shallow copy. In this process, B is attached to the same memory block as A. This is otherwise known as address copy.
This results in a situation in which same data is shared between A and B, thus modifying the one will alter the other. The original memory block of B is now no longer referred to from anywhere. If the language does not have automatic garbage collection the original memory block of B has probably been leaked.
The advantage of shallow copies is that their execution speed is fast and does not depend on the size of the data.
Bitwise copies of objects which are not made up of a monolithic block are shallow copies.

Deep copy

A deep copy in progress.
A deep copy having been completed.
A deep copy in progress.

A deep copy having been completed.
An alternative is a deep copy. Here the data is actually copied over. The result is different from the result a shallow copy gives. The advantage is that A and B do not depend on each other but at the cost of a slower more expensive copy.