# What is the Shallow Copy and DeepCopy

**URL:** <https://discourse.slicer.org/t/what-is-the-shallow-copy-and-deepcopy/11615>\
**Category:** Development\
**Created:** [May 19, 2020, 10:12am UTC](https://discourse.slicer.org/t/what-is-the-shallow-copy-and-deepcopy/11615 "2020-05-19T10:12:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![loubna](https://avatars.discourse-cdn.com/v4/letter/l/cab0a1/32.png) [@loubna](https://discourse.slicer.org/u/loubna)\
**Post date:** [May 19, 2020, 10:12am UTC](https://discourse.slicer.org/t/what-is-the-shallow-copy-and-deepcopy/11615/1 "2020-05-19T10:12:51Z")

</div>

Hi to everyone;

SomeOne can tell me what is the difference between Shallow Copy, DeepCopy and simple affectation?

for exemple: what is the difference between:

1- vtkImagedata\* image = filter-\>GetOutput();  
2- image -\>ShallowCopy (filrer-\>GetOutput());  
3- image-\> DeepCopy(filter-\>GetOutput());

Thank’s in advance

---

<div class="post-metadata">

**Author:** ![James\_Hoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/james_hoctor/32/6895_2.png) [@James\_Hoctor](https://discourse.slicer.org/u/James_Hoctor)\
**Post date:** [May 19, 2020, 2:19pm UTC](https://discourse.slicer.org/t/what-is-the-shallow-copy-and-deepcopy/11615/2 "2020-05-19T14:19:20Z")

</div>

[This wiki page](https://en.wikipedia.org/wiki/Object_copying) describes deep versus shallow copy in general, but you likely want to know about the specific differences in vtkImageData. In particular, [this part of the VTK documentation](https://vtk.org/doc/nightly/html/classvtkDataObject.html#a04a5fb60bdbc929ce84f0cd14d911dbe) indicates that the deep copy copies pipeline connections that are not copied in the shallow copy. Perhaps [the VTK discourse](https://discourse.vtk.org/) would be a good place for this question.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 19, 2020, 11:31pm UTC](https://discourse.slicer.org/t/what-is-the-shallow-copy-and-deepcopy/11615/3 "2020-05-19T23:31:45Z")

</div>

The wiki page describes this well. In practice, ShallowCopy can be much faster for large data sets, but you need to be very careful when you use it, as data sharing with the source node may have unintended side effects. Most often ShallowCopy is used with a source object that gets deleted soon after the copy.
