copying objects Flashcards

1
Q

reference copy

A

the new object in the stack references the object in the heap and its attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

shallow copy

A

the new object in the stack references an new object in the heap, but its references point to the original objects attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

deep copy

A

the new object in the stack references a completely new object with a new copy of the attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

when to use reference…

A

pros: fasted, least amount of space used
cons: if class is mutable, aliasing must be avoided (need true copies to prevent privacy leaks and modifications from outside)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

when to use shallow…

A

pros: faster than deep copy, less space used than deep copy
cons: still has aliases (bad, only if the class is mutable)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

when to use deep…

A

pros: no aliasing (necessary for mutable classes)
cons: slowest, takes up the most space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly