[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: When are unused overlays garbage collected?
From: |
Marcin Borkowski |
Subject: |
Re: When are unused overlays garbage collected? |
Date: |
Thu, 27 May 2021 18:20:46 +0200 |
User-agent: |
mu4e 1.1.0; emacs 28.0.50 |
On 2021-05-26, at 14:30, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Marcin Borkowski <mbork@mbork.pl>
>> Cc: help-gnu-emacs@gnu.org
>> Date: Wed, 26 May 2021 06:53:42 +0200
>>
>> But what would happen if I (delete-overlay my-overlay), then it gets
>> garbage collected, and then I (move-overlay my-overlay ...)?
>>
>> I just performed a simple experiment - I manually created an overlay in
>> a temporary buffer, bound a variable to it, deleted it, and called
>> (garbage-collect) - and C-h v'ing that variable still said:
>>
>> aqq’s value is #<overlay in no buffer>
>>
>> so I assume it was /not/ GCed.
>
> It wasn't GCed because it was referenced from a variable.
Stupid me, of course.
>> >> My guess would be that if the overlay is "deleted" (so it is not
>> >> attached to any buffer, either by means of `delete-overlay' or when its
>> >> buffer is killed) /and/ it can't be referenced from Elisp (e.g., there
>> >> is no variable bound to it).
>> >
>> > That's not entirely true. An overlay (like any other Lisp object)
>> > that was deleted will not be collected as long as some variable
>> > _actually_references_ it. That could be a Lisp variable or a C
>> > variable not exposed to Lisp. The difference between what I wrote and
>> > what you wrote is that the reference must actually exist, not only be
>> > possible.
>>
>> I am not sure if I grasp that difference. Can you provide an example of
>> a situation when an object does not have an "actual reference" but still
>> "can be referenced"? Do you mean e.g. it being an element of a list
>> bound to some variable?
>
> No, that's not the essence of the difference. You said, above, "it
> can't be referenced from Lisp". My point is that "can't" doesn't cut
> it, because an object can be GCed even if it _can_ be referenced.
> What matters is that it _is_not_ referenced, even though it _can_be_.
>
> IOW, any object can potentially be referenced by some variable, but GC
> only avoids recycling an object if some other object actually (not
> potentially) references it. The GC's "mark" phase scans all the live
> Lisp objects and marks any other objects referenced by those live
> objects, recursively. Any marked object will not be recycled by the
> "sweep" phase.
I think we misunderstood each other. By "can't be referenced from Lisp"
I meant "there was no object - like a variable - referencing it". IOW,
no possible Lisp code could get me a reference to that overlay. So we
agree, we just used words in a different way.
>> Well, I meant something different - an overlay that is "live" in some
>> buffer, but no variable is bound to it. Such an overlay /can/ be
>> referenced with `overlays-in' / `overlays-at', so obviously cannot be
>> GCed, right?
>
> No live overlay in a live buffer will ever be GCed, because when GC
> marks live buffers, it also marks the overlays in that buffer by
> walking the linked list of the buffer's overlays.
Yes, that was what I meant. Thanks.
--
Marcin Borkowski
http://mbork.pl
- When are unused overlays garbage collected?, Marcin Borkowski, 2021/05/24
- Re: When are unused overlays garbage collected?, Emanuel Berg, 2021/05/24
- Re: When are unused overlays garbage collected?, Eli Zaretskii, 2021/05/24
- Re: When are unused overlays garbage collected?, Eli Zaretskii, 2021/05/26
- Re: When are unused overlays garbage collected?,
Marcin Borkowski <=
- Re: When are unused overlays garbage collected?, Eli Zaretskii, 2021/05/27
- Re: When are unused overlays garbage collected?, Marcin Borkowski, 2021/05/28
Re: When are unused overlays garbage collected?, Stefan Monnier, 2021/05/24