title: What is the purpose of $.cache in jQuery?
body: <p>I see that the event handlers registered through <code>.on()</code> are held in <code>$.cache</code>.
  I also see that the event handlers are also held in <code>$(elem).data()</code>.</p>
  
  <p>The objects held in <code>$.cache</code> refer to the DOM nodes on which the events are registered. This leads to memory leak when the DOM nodes are detached, and this makes <code>.off()</code> calls mandatory.</p>
  
  <p>I have a situation where I don't know when the DOM node (to which I attached the event handler) is being detached. While I can hold the reference to that DOM node in my code and call <code>.off()</code> to clean up, it doesn't seem nice, because it is not straightforward to know when the DOM node is being removed.</p>
  
  <p>What is the best way to do this? </p>