<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAutoreleasePool/drain",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAutoreleasePool(im)drain"
  },
  "title" : "drain"
}
-->

# drain

In a reference-counted environment, releases and pops the receiver; in a garbage-collected environment, triggers garbage collection if the memory allocated since the last collection is greater than the current threshold.

```
- (void) drain;
```

## Discussion

In a reference-counted environment, this method behaves the same as <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-c.protocol/release>. Since an autorelease pool cannot be retained (see [`NSAutoreleasePool`](/documentation/Foundation/NSAutoreleasePool)), this therefore causes the receiver to be deallocated. When an autorelease pool is deallocated, it sends a <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-c.protocol/release> message to all its autoreleased objects. If an object is added several times to the same pool, when the pool is deallocated it receives a <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-c.protocol/release> message for each time it was added.

### Special Considerations

In a garbage-collected environment, `release` is a no-op, so unless you do not want to give the collector a hint it is important to use [`drain`](/documentation/Foundation/NSAutoreleasePool/drain) in any code that may be compiled for a garbage-collected environment.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)