diff --git a/comment_alter_taxonomy.module b/comment_alter_taxonomy.module
index 2dc13c1..b3b434a 100644
--- a/comment_alter_taxonomy.module
+++ b/comment_alter_taxonomy.module
@@ -772,3 +772,25 @@ function _comment_alter_taxonomy_callback($file, $function) {
   include_once drupal_get_path('module', 'comment_alter_taxonomy') .'/'. $file;
   return call_user_func_array($function, $args);
 }
+
+/**
+ * Implements hook_cron().
+ */
+function comment_alter_taxonomy_cron() {
+  // Find all orphan (no longer assigned) terms in configured vocabularies to
+  // delete them.
+  if ($vids = array_keys(array_filter(variable_get('comment_alter_taxonomy_vocabularies', array())))) {
+    $placeholders = db_placeholders($vids);
+    // Filter on {term_data}.vid, since {term_node}.vid is the {node}.vid.
+    // Limited to 100 terms per cron run.
+    $result = db_query_range("SELECT t.tid
+      FROM {term_data} t
+      LEFT JOIN {term_node} tn ON tn.tid = t.tid
+      WHERE t.vid IN ($placeholders) AND tn.tid IS NULL
+    ", $vids, 0, 100);
+
+    while ($tid = db_result($result)) {
+      taxonomy_del_term($tid);
+    }
+  }
+}
