# ApplyRetentionPolicy()

> Deletes the oldest builds in the build history so that no more than BuildHistory.BuildHistoryLimit remain.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor.Build](/engine/6000.6/script-reference/unityeditor/build.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public static int ApplyRetentionPolicy()
```

### Returns

| Type                                                       | Description                                                    |
| ---------------------------------------------------------- | -------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The number of build metadata directories successfully deleted. |

### Remarks

If [BuildHistory.BuildHistoryLimit](/engine/6000.6/script-reference/unityeditor/build/buildhistory/buildhistorylimit.md) is 0, or the current build count is at or below the limit, no entries are removed and this method returns 0.

If a folder cannot be deleted (for example, due to a file lock or a permissions issue), a warning is logged and the operation continues with the remaining entries.

Additional Resources: [BuildHistory.BuildHistoryLimit](/engine/6000.6/script-reference/unityeditor/build/buildhistory/buildhistorylimit.md)
