"Add to collection" is replacing objects instead of adding

collections
activities

#1

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?

LecturaCaso.xaml (60.8 KB)

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…

Thanks in advance
Stratum


#2

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.

Cheers
Stratum


Add to Dictionary Activity is replacing the dictionary values in dictionary with latest values for all keys
#3

Because these are reference types - they dont store values, they only point to them.
On the go now, but this could help


Add to Dictionary Activity is replacing the dictionary values in dictionary with latest values for all keys
#4

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?

Thanksk again,
Stratum


#5

Hey @Stratum

Can you please explain this again?

I am using Assign activity

selector= new list(ofString,list(ofString))
Is this the correct format?


#6

Hi @SHAISTA,

if you are using Key value pair go to Dictionary.

create->selector= new Dictionary(of String, List(of String))

Regards,
Arivu


How to initialize a collection variable
#7

Hi @arivu96

Is there any other way instead of using the key value pair?


#8

Hi @SHAISTA,
if you are using ofString,list(ofString) you need to use Dictionary.

Regards,
Aeivu


#9

Yes i understood that.