Re: Introducing "toggle references"

Dnia 28-04-2005, czw o godzinie 13:10 -0400, Owen Taylor napisał:
> On Thu, 2005-04-28 at 13:08 +0200, Alexander Larsson wrote:
> > Ok, I have a better idea.
> > What if we use the toggle references in the other way.
> This is what gtk2-perl does currently ... it works better *if*
> it's implementable in the language runtime.


> So, perhaps the hybrid setup where we use the two-part object for
> foreign references (references to GObjects not created from Java)
> and use toggle references for native references (references to GObjects
> created from Java) would solve most of the problems.
> Pretty complex, however. :-)

Sorry if by "implementable in the language runtime" you meant precise
answer to my question, but I'm not sure about that, so I will ask
anyway :)

Is it possible in Java to implement a scheme like that:

- When Proxy A is created, it refs (via normal reference) GObject, and
is itself ref'd by GObject. Proxy A is at this point referenced by the
runtime, so its recount is >= 2.

- At some point, Proxy A is unrefed in the runtime, and so its refcount
drops to 1. Now the mechanism kicks in that does:
so effectively it converts normal ref to toggle_ref. Now all the
references to GObject are toggle refs (rest of the setup is the same as
in your example, so there's Proxy B that's not referenced by B runtime),
so it can proceed and begin converting them to weak refs. This would
break the cycle, allowing it to be collected.

The basic question here is, how much can Java object do when its
reference count changes? If it can make sure that on refcount == 1
references to underlying GObject are made into toggle references, then
we can have proper cycle management scheme that will collect cycles when
possible, but not before.

Again, sorry if it's exactly your argument, but I just don't know that
and don't have time to do proper homework right now.


Maciej Katafiasz <ml mathrick org>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]