In addition to keeping a list of pointers to the object, you'll need to 
traverse them in some way to find cycles and free storage with cycles, but not 
pointed to by any non-cycles.  That pass should not be done every time you 
break a pointer link because it can be very expensive, just as garbage 
collection is.  You could do it periodically, maybe every so many allocations 
or so many seconds -- but if you do that, you've basically written a garbage 
collector.

  Remember that an object can be part of more than one cycle, and you have to 
know how many of those refs are "cyclic" refs, and how many (if any) aren't 
from cycles.  That's non-local knowledge.  What I'm saying is that it's not an 
easy think to calculate, and there's a reason that garbage collectors tend to 
be slow :-)

--- On Sat, 1/10/09, Yu Feng <[email protected]> wrote:

> From: Yu Feng <[email protected]>
> Subject: Re: [Vala] use weak and var together
> To: "Jürg Billeter" <[email protected]>
> Cc: [email protected]
> Date: Saturday, January 10, 2009, 12:45 PM
> On Sat, 2009-01-10 at 19:36 +0100, Jürg Billeter wrote:
> > On Sat, 2009-01-10 at 13:07 -0500, Yu Feng wrote:
> > > On Sat, 2009-01-10 at 18:35 +0100, Jürg Billeter
> wrote:
> > > > Right, but I'm not sure that you need to
> change anything in the unref
> > > > function to get dispose functionality
> working. Can you explain more
> > > > specifically what you can't get working
> with the current possibilities?
> > > > 
> > > 
> > > Yes I can do this:
> > > 
> > > class Object {
> > >    Object ref_to_there;
> > >    Object ref_to_here;
> > >    private disposed = false;
> > >    public virtual void dispose() {
> > >          /*release references here*/
> > >       ref_to_there = null;
> > >       ref_to_here = null;
> > >    }
> > >    private void run_dispose() {
> > >       if(disposed) return;
> > >       disposed = true;
> > >       dispose();
> > >    }
> > >    public void destroy() {
> > >       Object holder = this; 
> > >       /*needed if invoked from a weak reference
> of this*/
> > >       run_dispose();
> > >       holder = null;
> > >    }
> > > }
> > > 
> > > Then Object.destroy can be used to manifestly
> break any cycle
> > > references.
> > > 
> > > I was thinking about auto-cycle-breaking but it
> is unfortunately beyond
> > > my knowledge.
> > 
> > Unfortunately, there is no magic trick to break
> reference cycles
> > automatically in a simple way. In general, this
> requires an additional
> > garbage or cycle collector which scans stack and heap.
> > 
> Is it basically to maintain a list of all pointers to the
> object? With
> some extension to vala compiler at AssignmentBinding
> perhaps we can have
> this list at a relatively cheap cost without scanning
> stacks and heaps.
> 
> 
> > Jürg
> > 
> 
> _______________________________________________
> Vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list


      
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to