title: Does garbage collection remove deleted items from a Doubly Linked List with the given code?
body: <p>I have a Doubly Linked List that each object has a data and a pointer to the next object and a pointer to the previous object like this:</p>
  
  <p><code>obj1 &lt;-&gt; obj2 &lt;-&gt; obj3 &lt;-&gt; obj4 &lt;-&gt;</code></p>
  
  <p>I use this code to remove <code>obj3</code> and <code>obj4</code>: assume <code>p</code> is the data of <code>obj2</code></p>
  
  <pre><code>let b = head;
  while(b.next!=null){
  b=b.next
  if(b.data === p){
  b.next = null;}}
  </code></pre>
  
  <p>In this way of deleting, the pointer to <code>obj3</code> is lost and so <code>obj3</code> and <code>obj4</code> are not accessible but <code>obj3</code> has the pointer to <code>obj2</code> in the <code>obj3.previous</code></p>
  
  <p>My question is: if I use this code to remove <code>obj3</code> and <code>obj4</code> will garbage collection remove <code>obj3</code> and <code>obj4</code> from the memory? If yes how does it understand that <code>obj3</code> is not accessible (will it iterate over the linked list? if yes will the operation take time of O(n)?). It is important to me to know how much the javascript garbage collection will slow down the runtime.(the list is so long and will take some time to iterate over)</p>