Q:  How can I delete a marker after it has been created?

I see how to create markers and how to move markers, but I see nothing in the manual about how to delete them:

1 Answer 1


Markers that point nowhere are garbage-collected. From the Elisp manual, node Overview of Markers:

Insertion and deletion in a buffer must check all the markers and relocate them if necessary. This slows processing in a buffer with a large number of markers. For this reason, it is a good idea to make a marker point nowhere if you are sure you don’t need it any more. Markers that can no longer be accessed are eventually removed (*note Garbage Collection::).

To make a marker point nowhere, use set-marker to set it to nil:

(set-marker my-marker nil)

Is that not enough for you? Can you explain why you want to explicitly (i.e., immediately) delete a marker?

  • Not original questioner but creating markers in a function calls into unknown code which could raise an error, I need to know if I should use unwind-protect and set-marker to nil in case of failure.
    – ideasman42
    Commented Oct 28, 2021 at 0:25
  • Sorry; I don't understand what you're looking for / asking. The question, not comments, is the place to clarify it. You might want to pose a separate question, showing some code or specifying the context more clearly etc.
    – Drew
    Commented Oct 28, 2021 at 4:29
  • I had the same question as the questioner, the "why" may be the same - they don't state why. I just mention if markers are created in code that might later error... this seems like a case where the script author may want to clean up - although that can be a question on it's own since I'm not sure of what's the best practice in this case.
    – ideasman42
    Commented Oct 28, 2021 at 5:55
  • Asked a related question emacs.stackexchange.com/questions/69117
    – ideasman42
    Commented Oct 28, 2021 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.