When creating markers, should code that may fail (a user defined function for example) clean-up after it's self?
So for example, new markers are created, the function of unknown origin is called, on error, set all markers positions to nil so they are garbage collected.
Is this important, or is going out of scope (with a let binding for example) enough to have these markers be garbage collected without the need for manual cleanup?
Here is a concrete example:
Will garbage collection handle this case?
(let ((marker (set-marker (make-marker) 14)))
;; This function might fail.
(funcall user-defined-fn))
Or is something like this needed?
(let ((marker (set-marker (make-marker) 14)))
;; This function might fail.
(unwind-protect
(funcall user-defined-fn))
;; Ensure garbage collection.
(set-marker marker nil))
https://www.gnu.org/software/emacs/manual/html_node/elisp/Overview-of-Markers.html notes:
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 (see Garbage Collection).
See also this related question.