On Thu, Nov 7, 2013 at 6:40 PM, K. Gadd <[email protected]> wrote:
> To contrive a scenario that might illustrate where event listeners aren't
> necessarily enough: Let's say I have an entity system for a game that is
> modelling thousands of independent entities that interact. In this system,
> entity A might decide to chase after entity B, so it grabs a reference to
> entity B in order to chase after it. Meanwhile, entity B might be chasing
> after entity C, so it has a reference to entity C. Now, let's say entity C
> and entity B both are removed from the simulation. At this point, as long as
> entity A is alive, so are B and C (in GC terms) even though the latter two
> are not participating in the simulation.

But if you were to rely on weak references for a use case like this,
you'd nondeterministically get strange behavior. Entity A will be
chasing something that is not in the simulation, until GC happens and
it fixes itself.

(As a bonus, the weirdness will happen in one implementation and not
another, and you and your users will blame the implementation. So
there will be pressure on implementers to reduce the nondeterminism by
doing GC more frequently—which trades off against other performance
measures.)

And in this case, it all seems unnecessary. There is apparently
already explicit code for both removing B and C, and later coping with
their disappearance (since the weak reference may go null). That code
could just as easily set a bit on B and C marking them as removed, and
then test that in the chasing code.

-j
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to