disposeGroup static method

void disposeGroup(
  1. String groupId
)

Removes every entry whose current groupId equals groupId. Subsequent lookup calls for those tokens return null.

Entries that were registered under groupId but later refreshed (cache hit) by a newer snapshot now carry the newer snapshot's groupId — those are NOT removed by this call. This is what lets older snapshot ids be disposed without invalidating refs the agent is still using.

No-op when no entry currently carries groupId.

Implementation

static void disposeGroup(String groupId) {
  // 1. Collect tokens to remove. Iterate before mutation to avoid
  //    concurrent-modification on the entries map.
  final List<String> toRemove = <String>[];
  final List<int> nodeIdsToRemove = <int>[];
  for (final MapEntry<String, RefEntry> entry in _entries.entries) {
    if (entry.value.groupId == groupId) {
      toRemove.add(entry.key);
    }
  }
  // 2. Drop entries.
  for (final String token in toRemove) {
    _entries.remove(token);
  }
  // 3. Drop dedupe-cache mappings whose token is gone. Iterate the
  //    node-id map separately because entries[X] just disappeared.
  for (final MapEntry<int, String> entry in _byNodeId.entries) {
    if (toRemove.contains(entry.value)) {
      nodeIdsToRemove.add(entry.key);
    }
  }
  for (final int nodeId in nodeIdsToRemove) {
    _byNodeId.remove(nodeId);
  }
}