diff --git a/flag.inc b/flag.inc
index 1f73c78..f634eed 100644
--- a/flag.inc
+++ b/flag.inc
@@ -194,6 +194,12 @@ class flag_flag {
         'unflag' => array(DRUPAL_AUTHENTICATED_RID),
       ),
       'weight' => 0,
+
+      // If this option is set to TRUE, any anonymous flags created in a
+      // session that has since expired will be deleted from the flag_content
+      // table in flag_session_api_cleanup(). The data in flag_counts will not
+      // be affected.
+      'delete_expired_flag_content' => TRUE,
     );
 
     // Merge in options from the current link type.
diff --git a/flag.module b/flag.module
index 11f8d1d..414d430 100644
--- a/flag.module
+++ b/flag.module
@@ -689,6 +689,21 @@ function flag_user_view($account, $view_mode) {
  * Clear out anonymous user flaggings during Session API cleanup.
  */
 function flag_session_api_cleanup($arg = 'run') {
+  // Get all flags which should be truncated.
+  $flags = flag_get_flags();
+  $fids = array();
+  foreach ($flags as $flag) {
+    if (!empty($flag->delete_expired_flag_content)) {
+      $fids[] = $flag->fid;
+    }
+  }
+
+  // Flags are configured to clean-up records by default, but if disabled on all
+  // flags, no need to do any work.
+  if (empty($fids)) {
+    return;
+  }
+
   // Session API 1.1 version:
   if ($arg == 'run') {
     $query = db_select('flag_content', 'fc');
@@ -700,6 +715,7 @@ function flag_session_api_cleanup($arg = 'run') {
       ->execute();
     foreach ($result as $row) {
       db_delete('flag_content')
+        ->condition('fid', $fids, 'IN')
         ->condition('sid', $row->sid)
         ->execute();
     }
@@ -707,7 +723,10 @@ function flag_session_api_cleanup($arg = 'run') {
   // Session API 1.2+ version.
   elseif (is_array($arg)) {
     $outdated_sids = $arg;
-    db_delete('flag_content')->condition('sid', $outdated_sids, 'IN')->execute();
+    db_delete('flag_content')
+      ->condition('fid', $fids, 'IN')
+      ->condition('sid', $outdated_sids, 'IN')
+      ->execute();
   }
 }
 
