I wrote the following code:
final Iterator<Entry<Label, Label>> it = dataLabels.entrySet().iterator();
while (it.hasNext()) {
final Map.Entry<Label, Label> pairs = it.next();
dataLabels.remove(pairs.getKey());
pairs.getValue().dispose();
pairs.getKey().dispose();
}
It iterates over a map of labels (type: Map<Label, Label>
) and dispose of each one of them (after removing it from the map).
I feel like this code does not do what I expect. I think that it stops iterating after the first loop (tried to add printed message to see the behavior).
Does the code do what I expect (disposing of all the labels)? If not, how to fix it?