How Do I Clean Up FutureAccessList?

FutureAccessList is used for retaining permissions when accessing IStorageItems during the lifetime of a process or between sessions. It has a limit of 1,000 entries; however, sometimes it’s easy to lose track of entries and fail to remove items that no longer exist or are no longer needed. This results in an exception when you try to add more items than the 1,000-item limit. The list doesn’t clean itself up, but the following code snippet removes items that no longer exist:

var fal = StorageApplicationPermissions.FutureAccessList;
var tokenList = fal.Entries.Select(entry => entry.Token).ToList();

foreach (var token in tokenList)
{
    try
    {
        // Will throw if it no longer exists.
        await fal.GetItemAsync(token);
    }
    catch (Exception)
    {
        fal.Remove(token);
    }
}