1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-29 07:58:21 +00:00

org-element: Fix memory leak in cache

* lisp/org-element.el (org-element--cache-put): Do not store objects
  within headlines in cache as headlines are not cached, and,
  therefore, never removed.  This prevents adding the same object in
  cache multiple times without ever garbage collecting it.
This commit is contained in:
Nicolas Goaziou 2014-03-12 14:53:47 +01:00
parent 1e402cee8b
commit 0a5f5117a3

View File

@ -5011,22 +5011,25 @@ the cache."
"Store ELEMENT in current buffer's cache, if allowed.
When optional argument DATA is non-nil, assume is it object data
relative to ELEMENT and store it in the objects cache."
(when (org-element--cache-active-p)
(if data (puthash element data org-element--cache-objects)
(when org-element--cache-sync-requests
;; During synchronization, first build an appropriate key for
;; the new element so `avl-tree-enter' can insert it at the
;; right spot in the cache.
(let ((keys (org-element--cache-find
(org-element-property :begin element) 'both)))
(puthash element
(org-element--cache-generate-key
(and (car keys) (org-element--cache-key (car keys)))
(cond ((cdr keys) (org-element--cache-key (cdr keys)))
(org-element--cache-sync-requests
(aref (car org-element--cache-sync-requests) 0))))
org-element--cache-sync-keys)))
(avl-tree-enter org-element--cache element))))
(cond ((not (org-element--cache-active-p)) nil)
((not data)
(when org-element--cache-sync-requests
;; During synchronization, first build an appropriate key
;; for the new element so `avl-tree-enter' can insert it at
;; the right spot in the cache.
(let ((keys (org-element--cache-find
(org-element-property :begin element) 'both)))
(puthash element
(org-element--cache-generate-key
(and (car keys) (org-element--cache-key (car keys)))
(cond ((cdr keys) (org-element--cache-key (cdr keys)))
(org-element--cache-sync-requests
(aref (car org-element--cache-sync-requests) 0))))
org-element--cache-sync-keys))))
;; Headlines are not stored in cache, so objects in titles are
;; not stored either.
((eq (org-element-type element) 'headline) nil)
(t (puthash element data org-element--cache-objects))))
;;;; Synchronization