jargon

Design patterns·Making things

you copied the object, edited the copy's list, and the original's list changed too.

Deep copy vs shallow copy

Also calleddeep clone, shallow clone, clone depth

A shallow copy duplicates the object and shares whatever its fields point at; a deep copy duplicates the reachable graph as well. Almost every default copy in every language is shallow, which is why the surprise is so common. Deep copies are expensive, must decide what to do about cycles and shared identity, and are usually a sign that immutable values would serve better.

Commonly confused with