diff --git a/java/res/values/config-common.xml b/java/res/values/config-common.xml
index ab16a9045c8c2703d2f6101696176ff3f6da461d..c92015288b543ff456bf8c9a0fb1cb0cdf5ec4aa 100644
--- a/java/res/values/config-common.xml
+++ b/java/res/values/config-common.xml
@@ -139,4 +139,8 @@
     <dimen name="config_accessibility_edge_slop">8dp</dimen>
 
     <integer name="config_user_dictionary_max_word_length">48</integer>
+
+    <!-- Personalization configuration -->
+    <!-- -1 means periocical wipe of the personalization dict is disabled. -->
+    <integer name="config_personalization_dict_wipe_interval_in_days">-1</integer>
 </resources>
diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
index f785835b86faf24df1ddfcb3d255810410af3642..7757d29103e1bdeb8b19a9f641ee9cd635b83a7f 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java
@@ -282,7 +282,9 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
             @Override
             public void run() {
                 if (mDictionaryWriter == null) {
-                    mBinaryDictionary.close();
+                    if (mBinaryDictionary != null) {
+                        mBinaryDictionary.close();
+                    }
                     final File file = getDictFile();
                     if (file.exists() && !FileUtils.deleteRecursively(file)) {
                         Log.e(TAG, "Can't remove a file: " + file.getName());
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 84ba7223abd27f4cc54a22ba3e32913f0dc5c7d9..7fb51830826551d2d8212aaf47ab0287befabccd 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -93,6 +93,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
 
     private static final String PREF_LAST_USED_PERSONALIZATION_TOKEN =
             "pref_last_used_personalization_token";
+    private static final String PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME =
+            "pref_last_used_personalization_dict_wiped_time";
     public static final String PREF_SEND_FEEDBACK = "send_feedback";
     public static final String PREF_ABOUT_KEYBOARD = "about_keyboard";
 
@@ -372,6 +374,14 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
         return StringUtils.hexStringToByteArray(tokenStr);
     }
 
+    public void writeLastPersonalizationDictWipedTime(final long timestamp) {
+        mPrefs.edit().putLong(PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME, timestamp).apply();
+    }
+
+    public long readLastPersonalizationDictGeneratedTime() {
+        return mPrefs.getLong(PREF_LAST_PERSONALIZATION_DICT_WIPED_TIME, 0);
+    }
+
     public static void writeEmojiRecentKeys(final SharedPreferences prefs, String str) {
         prefs.edit().putString(PREF_EMOJI_RECENT_KEYS, str).apply();
     }