diff --git a/bridge/src/main/java/com/livefront/bridge/BridgeDelegate.java b/bridge/src/main/java/com/livefront/bridge/BridgeDelegate.java index 3fa262d..c7a5285 100644 --- a/bridge/src/main/java/com/livefront/bridge/BridgeDelegate.java +++ b/bridge/src/main/java/com/livefront/bridge/BridgeDelegate.java @@ -15,9 +15,7 @@ import com.livefront.bridge.wrapper.WrapperUtils; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Set; import java.util.UUID; import java.util.WeakHashMap; @@ -28,18 +26,11 @@ class BridgeDelegate { private static final String KEY_BUNDLE = "bundle_%s"; private static final String KEY_UUID = "uuid_%s"; - /** - * Time (in milliseconds) to wait between attempts to automatically clear stale data. - */ - private static final int AUTO_DATA_CLEAR_INTERVAL_MS = 100; - private boolean mIsClearAllowed = false; private boolean mIsFirstRestoreCall = true; - private long mLastClearTime; private Map mUuidBundleMap = new HashMap<>(); private Map mObjectUuidMap = new WeakHashMap<>(); private SavedStateHandler mSavedStateHandler; - private Set mRecentUuids = new HashSet<>(); private SharedPreferences mSharedPreferences; BridgeDelegate(@NonNull Context context, @@ -61,7 +52,6 @@ void clear(@NonNull Object target) { } void clearAll() { - mRecentUuids.clear(); mUuidBundleMap.clear(); mObjectUuidMap.clear(); mSharedPreferences.edit() @@ -70,7 +60,6 @@ void clearAll() { } private void clearDataForUuid(@NonNull String uuid) { - mRecentUuids.remove(uuid); mUuidBundleMap.remove(uuid); clearDataFromDisk(uuid); } @@ -81,30 +70,6 @@ private void clearDataFromDisk(@NonNull String uuid) { .apply(); } - /** - * Attempts to clear data associated with references held weakly that have been cleared. Note - * that there is no guarantee of success, as some references may still be held by the system - * longer than is actually necessary. - */ - private void clearStaleData() { - long currentTime = System.currentTimeMillis(); - if (currentTime - mLastClearTime < AUTO_DATA_CLEAR_INTERVAL_MS) { - // Avoid too many checks during the same stop event - return; - } - mLastClearTime = currentTime; - System.gc(); - - // Remove all the remaining UUIDs in the object map from the recent UUID list. Anything - // left represents objects that were garbage collected, so we should clear up any saved - // state associated with them. - Set staleUuids = new HashSet<>(mRecentUuids); - staleUuids.removeAll(mObjectUuidMap.values()); - for (String uuid : staleUuids) { - clearDataForUuid(uuid); - } - } - private String getKeyForEncodedBundle(@NonNull String uuid) { return String.format(KEY_BUNDLE, uuid); } @@ -195,10 +160,8 @@ void saveInstanceState(@NonNull Object target, @NonNull Bundle state) { return; } WrapperUtils.wrapOptimizedObjects(bundle); - mRecentUuids.add(uuid); mUuidBundleMap.put(uuid, bundle); writeToDisk(uuid, bundle); - clearStaleData(); } private void writeToDisk(@NonNull String uuid,