# PreDestroy class

Marks a method to be invoked before a pod is destroyed.

Jetleaf automatically detects methods annotated with `@PreDestroy` and calls them during pod shutdown or context close.

This is typically used for:

- Releasing resources (database connections, sockets, file handles).
- Stopping background workers.
- Flushing in-memory caches.

### Rules

- Must be a no-arg method.
- Return type should be `void` or `Future<void>`.
- Only applied to methods (not classes or fields).

### Example — Synchronous Cleanup

    @Service()
    class CacheManager {
      final _cache = <String, String>{};

      void put(String key, String value) => _cache[key] = value;

      @PreDestroy()
      void clearCache() {
        print("Clearing cache before shutdown...");
        _cache.clear();
      }
    }

### Example — Asynchronous Cleanup

    @Service()
    class WorkerPool {
      final _workers = <Worker>[];

      @PreDestroy()
      Future<void> shutdownWorkers() async {
        for (final worker in _workers) {
          await worker.stop();
        }
      }
    }

Inheritance
  - Object
  - ReflectableAnnotation
  - PreDestroy
Annotations
  - @Target({TargetKind.method})

## Constructors

PreDestroy.new()
  Marks a method to be invoked before a pod is destroyed.
  const

## Properties

annotationType → Type
  Returns the annotation _type of this annotation.
  no setter override
hashCode → int
  Returns a hash code consistent with equality definition.
  no setter inherited
runtimeType → Type
  A representation of the runtime type of the object.
  no setter inherited

## Methods

equals(Object other) → bool
  Checks whether the given object is logically equivalent to this annotation.
  inherited
noSuchMethod(Invocation invocation) → dynamic
  Invoked when a nonexistent method or property is accessed.
  inherited
toString() → String
  Returns a string representation of this annotation.
  inherited

## Operators

operator ==(Object other) → bool
  Checks if this annotation is equal to another object.
  inherited