---
title: collectIfNeeded
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/nsgarbagecollector/collectifneeded
---

# collectIfNeeded

Tells the receiver to collect if memory consumption thresholds have been exceeded.

## Declaration

```occ
- (void) collectIfNeeded;
```

## Discussion

Discussion You use this method to indicate to the collector that there is an opportunity to perform a collection. Collection is subject to interruption on user input.

## See Also

### Triggering Collection

- [collectExhaustively](foundation/nsgarbagecollector/collectexhaustively.md)
