And, in addition to what @tomasz86 said, from what I have read on this forum I have always believed it to be run as a "housekeeping" routine rather than directly linked to the deletion of a note. I'm not a code guru so I could be wrong.
EDIT:
The below is a post by Laurent, admittedly it's a bit old, giving insight into the method for deleting unused resources.