I had some problems with this function causing too much garbage, and as a result, the GC ran too often. So I changed it, so I wouldn’t create a new List, but just fire the functions of the list during the search.
As you can see in the first version, I obtain a new List only holding valid objects, and then fire them one by one afterwards. In the second version, the new version, I just iterate through the original list, and fire the functions whenever the same requirements as in version one has been met. But it doesn’t work. And I simply don’t understand why, and I’m sure I’m overlooking something. Please have a look, and help me out here ![]()
Version 1. Works perfectly, but generates a little too much garbage due to a new List being generated.
public void UpdateOutputs(Activator.Sender output, List<DataWrapper> data = null, PageObject specificReceiver = null)
{
List<Activator> outputActivator = null;
if (specificReceiver == null) {
outputActivator = activators.FindAll(c => c.sender == output);
} else {
outputActivator = activators.FindAll(c => c.sender == output c.receiverOwner == specificReceiver);
}
if (outputActivator != null)
{
for (int i = 0; i < outputActivator.Count; i++) {
outputActivator[i].DoSend(data);
}
}
}
Version 2. Doesn’t work. The system will freeze in what feels like an infinite loop, though it doesn’t seem to be this function being stuck. I tried making a bailOut procedure, to make sure the loop had a way of exiting, but that didn’t help
public void UpdateOutputs(Activator.Sender output, List<DataWrapper> data = null, PageObject specificReceiver = null)
{
for (int i = 0; i < activators.Count; i++) {
if (specificReceiver == null) {
if (activators[i].sender == output) {
activators[i].DoSend(data);
}
} else {
if (activators[i].sender == output activators[i].receiverOwner == specificReceiver) {
activators[i].DoSend(data);
}
}
}
}
Do you see any difference that could cause this?