# destroyPod method

1. @protected

Future<void> destroyPod(

1. String name,
2. Object pod

)
inherited

Destroy the given pod.

This method performs the actual pod destruction including:

- Dependency destruction
- Disposable pod cleanup
- Contained pod destruction
- Dependency map cleanup

`name`: The name of the pod being destroyed `pod`: The pod instance to destroy (may be null)

Example:

    final pod = registry.getSingleton('userService');
    registry.destroyPod('userService', pod);

## Implementation

    @protected
    Future<void> destroyPod(String name, Object pod) async  {
      destroyDependentPods(name);

      // Actually destroy the pod now
      try {
        if (pod is DisposablePod) {
          await pod.onDestroy();
        }

        if (pod is Closeable) {
          await pod.close();
        }

        if (pod is StreamSubscription) {
          await pod.cancel();
        }
      } on Exception catch (e) {
        onSuppressedException(e);
      }

      // Trigger destruction of contained pods
      Set<String>? containedPods;
      synchronized(_containedPods, () => containedPods = _containedPods.remove(name));

      if (containedPods != null) {
        for (final containedPodName in containedPods!) {
          destroySingleton(containedPodName);
        }
      }

      // Remove destroyed pod from other pods' dependencies
      synchronized(_dependentPods, () {
        for (final dependentName in _dependentPods.keys.toList()) {
          final dependents = _dependentPods[dependentName];
          dependents?.remove(name);
          if (dependents?.isEmpty == true) {
            _dependentPods.remove(dependentName);
          }
        }
      });

      // Remove destroyed pod's own dependencies from the registry
      _dependenciesForPods.remove(name);
    }