On Mon, Sep 17, 2012 at 4:53 AM, Yury Semikhatsky <yu...
> This would require storing references to all objects accessible from the
> scope chain and may lead to memory leaks caused by DevTools keeping the
> objects alive. Although I believe the feature can be useful I don't think we
> should blindly store the whole scope chain.
Rather than storing the references, one could copy them into
'representation' objects which only reference other representation
objects not the heap. The representation for primitives would be
primitives. Representation of the DOM would be a string like "<input
type='text'>...". So the result object would be large but it would not
point outside of itself; as soon as the console is cleared the large
object would be GC fodder. (This is similar to rendering the object to
text without actually rendering it).
For small programs or large closures each representation could be
larger than the program heap. To reduce the performance impact,
console.scope() could take a "depth" argument, where leaves at depth
are rendered to strings. Thus console.depth(1) would give the same
picture as Brian's blog post but the twistys would all give
"console.scope rendered at depth 1" or some such.