Strange behaviour of lists and local variables

Hello,
Let my explain my bug with the help of the photo:

So I have 2 lists and 2 local variables. Let’s do this in steps…

  1. I initialize the second list [lista_mod] to my first list [lista];
  2. I make operations on the second list [lista_mod];
  3. The first list [lista] is untouched;
  4. The second list is OK, after appending everything goes as I want.
  5. BOOM, my first list [lista] is changed excatly to the point as the second list.
  6. At the end nr 1 list = nr 2 list. It looks like these two list share the same memory place.

It makes my work harder. The picture is a small fragment of my JSON parser.

I got this bug earlier. I had to add splitted list to variable instead of just the list because it was writing different list to it.

IT WORKS :laughing:

But still, I need an explanation. Why this happens?

As far as I know “copy list” is the right way to duplicate the memory content of a list.

copylist

1 Like

Thank you, it works!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.