Hi!
On Fri, Oct 13, 2017 at 9:27 AM, Nicolas Chevobbe <
nche...@mozilla.com>
wrote:
> Hello devtoolers,
>
> When we log a variable in the console panel, if it is not a primitive an
> ObjectActor is created so we can use it as a reference for future
> operations (fetching properties mainly, since we only send a "preview" in
> the packet).
> Then when we don't need the actor anymore (e.g. when the console is
> cleared), we can release it so it does not consume unnecessary memory.
> One of the feature of the ObjectActor is that for a given variable, we can
> create multiple actors.
> if we take the following code :
>
> ```
> var a = { foo: { bar: 1 } };
> console.log(a)
> ```
>
> We'll end up with 2 actors, one for `a`, and another one for the inner `{
> bar: 1 }` object .
>
I thought we used a weak map to ensure that each object only ends up with
a single actor? Is that not the case? Or not the case anymore? It was on
the object actor pool IIRC... perhaps that is only for the debugger's
object actors and not the console's?
With multiple actors for the same object, beyond a general grating against
aesthetics of perceived efficiency devoid of any measurements, there are
opportunities for the actors to get out of sync. As you allude to, keeping
one thing up to date is usually simpler than keeping many things up to date.
> We were thinking that it would be nice to have something in the ObjectActor
> which would allow us to release all the actors in a grip by simply calling
> release on the "root" ObjectActor (in the code example, it would be the `a`
> actor only).
>
This sounds an awful lot like what the actor pools were created for. Have
you looked into using them in this situation?
>
> We do have a concern though, would there be some cases when releasing a
> parent we *do not* want to release its children ? We don't have anything
> that comes to mind, but you may have specific case that would need such
> thing.
>
If there were such a scenario, it would be best to re-parent the children
to the about-to-be-released-parent's parent or actor pool. That way the
tree ownership discipline is preserved.
Hope this is helpful, it's been a while since I touched this stuff :-p
Cheers!
Nick