Deep v. Shallow Copies

When you copy a thing, are references in that thing to other things copied as references or are copies made of the things referenced?

When copying a list of things, are just the references in the list copied, or do you get back a list of new things copied from the thinsg in the original list?


1 Like

Allright, based on experiments, th answer is both :frowning:
When you copy a list of objects, the objects in the list get duplicated, but their fields get shallow copied.

SO I’m now beating my head against how to deep copy a list of lists…

Edit: I could do it with a recursive back-end workflow. I wish there was a simpler way though…

1 Like

I think a bit more explanation on “deep copy” would help as we may well be thinking about different things.

Agree with @NigelG. What is meant by deep copy?

Deep and Shallow copy are computer science terms.

A deep copy of a variable copes the value of the variable so you have 2 separate variables.
A shallow copy just copies a refence to a variable (often, but nto always, a memory address) so you have a single variable referred to in multiple ways.

In databases, the idea extends by analogy. A deep copy is a new record. A shallow copy is another field referring to the same primary key.


I don’t think Bubble will like it, as there is the potential for it to run forever.

You can copy a list of things…

You can try using backend workflows to recursively create Things and then copy the contents. For example, let’s say a User has a list of Posts. Instead of copying User, create a new User, create a list of new Posts, and copy the contents of the posts.


It seems nested recursive backend workflows is the way to go. Custom-built as opposed to any vanilla action specific for this use case.

Yeah that seems to be the answer for bubble.

Avoiding infinite loops on a directed potentially cyclic graph is a relatively easy computer science problem, btw. You just use a node index for already visited nodes. Basic hashtable works great for this.