Computer science: shallow copy vs deep copy

Self-tutoring about computer science: the tutor mentions the difference between shallow and deep copy.

A shallow copy of an object is a new name for it. When the original changes, so will the shallow copy. Moreover, a change to the shallow copy will likewise change the original. After the shallow copy, there is only one actual object, but now it has an extra name.

A deep copy produces a new object with a new memory location. At first its elements are identical to the original. Henceforth, however, it’s independent of the original; either can change without affecting the other.

Source:

stackoverflow.com

Jones, Darren. JavaScript: Novice to Ninja, 2nd edition. Collingwood: SitePoint Pty, 2017.

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply