diff --git a/lib/tern.js b/lib/tern.js
index <HASH>..<HASH> 100644
--- a/lib/tern.js
+++ b/lib/tern.js
@@ -137,7 +137,10 @@
       var file = this.findFile(name);
       if (file) {
         this.needsPurge.push(file.name);
-        this.files.splice(this.files.indexOf(file), 1);
+        for (var i = 0; i < this.files.length; i++) {
+          if (this.files[i] == file) this.files.splice(i--, 1);
+          else if (this.files[i].parent == name) files[i].parent = null;
+        }
         delete this.fileMap[file.name];
       }
     },
Don't leave dangling parent pointers when deleting a file

Issue #<I>