Search This Blog

Tuesday, December 15, 2009

ShallowCopy and Deepcopy

Difference between Shallow Copy and deep copy.

Shallow copy copy creates new object and copies references in the object and wont copy the referenced objects.

Eg: "X" is an object and having references to objects "A" and "B" .
Now object "X1" is created as shallow copy to object "X" . now X1 contains references to "A" and "B".
i.e both X and X1 are pointing to objects "A" and "B".If any non static variables present in "X" those are also copied directly bit-by-bit into "X1".

In deep copy "X1" contains references to "A1","B1" which are copies of "A"&"B".

Best Regards
Palle Technlogies
http://techpalle.com