Immediate closing of iterators

Chris Hansen renselp at gmail.com
Thu Dec 21 14:43:59 PST 2006


> >   Also, a generator doesn't have an iterator::get
> > method since that would complicate the question of who "owns" it.
>
> This is not a problem in the ES4 proposal, or in Python.  Ownership
> of storage and close are coupled only to guarantee that close happens
> eventually, even if the client code fails to call gen.close()
> explicitly.  More below.

By the "owner" of a generator I meant the loop responsible for closing
it, not the storage owner.  But maybe there should be an iterator::get
method on generators -- people just have to be aware that loops close
generators, which might be confusing.

> > That only "solves" Jeff's problem by disallowing it (ta-daa! ;-) but
> > it does away with the need for  any kind of finalization, prompt or
> > not.  In my experience (from java) GC finalization is something you
> > want to steer well clear of.
>
> Finalization is definitely two-phase in systems that have to support
> close (which might resurrect the generator) and then release its
> storage.  Those of us burdened with GC-based memory management for ES/
> JS/AS implementations have to dance with the GC here.

I see, you would still need finalization to guarantee that generators
not created by loops are eventually closed.  But is that a guarantee
you actually need to make -- especially if it complicates the
implementation and potentially opens the browser up for a new type of
DOS attacks?  C# doesn't guarantee this.  In java, even though you're
guaranteed that finalizers will be run, they advise people not to rely
on them.  Instead, it could just be part of the contract on Generator:
if you create it, you have to close it (unless you know that close is
a no-op).  It's not something that people are likely to do often and I
think they will close explicitly anyway rather than rely on
finalization, which adds a source of nondeterminism to a program.
Especially if the browser might actually cancel close ops.

Also, having finalization will mandate a non-conservative GC.


-- Chris



More information about the Es4-discuss mailing list