ecmascript-object-observe icon indicating copy to clipboard operation
ecmascript-object-observe copied to clipboard

ObserverCallbacks continues growing with dead callback

Open naqtn opened this issue 10 years ago • 3 comments

Object.observe() appends the callback to [[ObserverCallbacks]] . On the other hand, Object.unobserve() does not care about [[ObserverCallbacks]] . Then [[ObserverCallbacks]] continues growing big with unused callback while the system runs.

I implemented current specification straight forward, then I encountered this problem.

I think Object.unobserve() should remove it. Or, somewhere in delivering steps (the end of AllChangeRecords ?) might be better point. because records in [[PendingChangeRecords]] could remain if Object.unobserve() immediately removes.

naqtn avatar Feb 23 '15 17:02 naqtn

The spec only describes semantics. Things like GC is unobservable. An implementation needs to make sure that it cleans up unreachable objects.

It is possible that we need to make something clearer in the spec here?

arv avatar Feb 23 '15 17:02 arv

The spec uses the term "List" which is an implementation specific data structure.

arv avatar Feb 23 '15 18:02 arv

(I posted a comment but it was unclear. I rewrite.)

I've thought even if internal property is not directly accessible via ECMAScript code, but acts like usual ECMAScript Object (especially reachability manner in this case). The event queue holds [[ObserverCallbacks]], and [[ObserverCallbacks]] holds "unused callback", and I think "unused callback" is reachable after Object.unobserve().

Is it incorrect?

If I misunderstand, who holds strong referrence? After Object.observe() called, the callback can be refered only from two paths. (User main program can release it. right?)

  1. user main program => observable => [[Notifier]] => [[ChangeObservers]] => record =([[Callback]])=> callback
  2. event queue => [[ObserverCallbacks]] => callback

If [[ObserverCallbacks]] behaves like weak referrence, how about first internal properties? And strictly when the callback becomes garbage Object.unobserve() after called?

P.S.

"List" which is an implementation specific data

Well.., I'll read the spec again carefully.

naqtn avatar Feb 23 '15 19:02 naqtn