diff --git a/java/com/google/gerrit/server/account/AccountState.java b/java/com/google/gerrit/server/account/AccountState.java index 34f4eb14ce..c8dc64cb0a 100644 --- a/java/com/google/gerrit/server/account/AccountState.java +++ b/java/com/google/gerrit/server/account/AccountState.java @@ -111,15 +111,24 @@ public class AccountState { ? externalIds.byAccount(account.getId(), extIdsRev.get()) : ImmutableSet.of(); + // Don't leak references to AccountConfig into the AccountState, since it holds a reference to + // an open Repository instance. + // TODO(ekempin): Find a way to lazily compute these that doesn't hold the repo open. + ImmutableMap> projectWatches = + accountConfig.getProjectWatches(); + GeneralPreferencesInfo generalPreferences = accountConfig.getGeneralPreferences(); + DiffPreferencesInfo diffPreferences = accountConfig.getDiffPreferences(); + EditPreferencesInfo editPreferences = accountConfig.getEditPreferences(); + return Optional.of( new AccountState( allUsersName, account, extIds, - Suppliers.memoize(() -> accountConfig.getProjectWatches()), - Suppliers.memoize(() -> accountConfig.getGeneralPreferences()), - Suppliers.memoize(() -> accountConfig.getDiffPreferences()), - Suppliers.memoize(() -> accountConfig.getEditPreferences()))); + Suppliers.ofInstance(projectWatches), + Suppliers.ofInstance(generalPreferences), + Suppliers.ofInstance(diffPreferences), + Suppliers.ofInstance(editPreferences))); } /**