Hey all,
I’m trying to build a complex array consisting of a List of Dictionaries (it goes deeper down the rabbithole, but that´s not an issue).
The flow (attached) goes through a loop that builds the dictionary and adds it to a list (of Dictionary). However, when I try to use the object further down the Main Flow, all it contains is the last dictionary added. When I check within the flow, I can see that it writes the dictionary to index 0 on every pass. What am I doing wrong?
Plan B would be to use invoke code and write that piece of code myself, but honestly, there’s no logical reason why the activity should behave like this, especially since I’m using the same activity to build the dictionary and it works just fine there…
This behaviour happens when I use the “clear collection” and “clear dictionary” activity on the arrays that feed the final list (after adding the completed dictionary to the final list). Once the testcase has been added to the list, whatever I do with the original containers should not matter but it does.
So here’s how I solved it. Instead of using the “clear collection / dictionary” activity, I re-instantiated all objects with assign → new list (of String) / new dictionary (of string, list (of string)).
I don’t know if this would be an issue further down the line, so I set all objects to “Nothing” before leaving this particular flow.
I would very much like to understand why “clear collection” affected the dictionary already added to the list, so anyone who could throw some wisdom my way would be very very welcome.
Hey thanks for the clarification, very helpful indeed. But why would it work if I create a new instance of the object with the same name then? wouldn’t it reference to the same Heap?
Also, if not, how do I know that using this way I get rid of the prior info in memory by setting the objects to nothing?