Re: Re: Re: my garbage collector sucks

"Mark Hahn" <[email protected]>
Newsgroups gmane.comp.lang.prothon.user
Message-ID <[email protected]>
"Greg Ewing" <[email protected]> wrote

> It seems to me you can get the same thing happening in Prothon code,
> too. Consider the following scenario:
>
>   a = [None]          # 1
>   b = [Something()]   # 2
>   a[0] = b[0]         # 3
>   b[0] = None         # 4
>
> Suppose the main thread has executed lines 1 and 2, and the marker has
> got as far as marking objects reachable from list a (of which there
> are none) but not list b. Then the marker gets timesliced out and the
> main thread executes 3 and 4, moving the Something instance from b to
> a. Then the marker marks objects reachable from list b, of which once
> again there are none. The marker has now finished its pass without
> having marked the Something instance, and erroneously concludes that
> it is garbage.
>
> Is there anything to prevent this sort of thing from happening?

It was months ago when I did the garbage collector and at the time I thought
I has it worked out.  I put in code to mark objects not only in the mark
phase but when new objects are created, when objects are touched or modified
and I think when objects are being pointed to and the pointers are mucked
with.  In general it never hurts to mark anything and everything involved
with any operation since such objects are obviously reachable and also it
does no harm to mark extra objects in any one pass.

You've got me wondering now and I need to go back and check my logic.  I
kind of feel like you feel when you go on a trip and you wonder if you left
the stove on.

The good news is that when an object is deleted early the bug tends to be
noticed.  The memory is reused quickly and two objects occupying one space
is messy.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.