Ah, yes, that creates some difficulty. I see two solutions here:

1. There should be some moment in time, when your object is reachable
via a context. You can look up its id at that moment and use it later.
2. You can make your object to reference some string, then implement a
debugger function that finds a string object in the heap by contents,
and proceed from this string.

As for the C++ implementation, this is how it can be traced:
 - debug-debugger.js:
DebugCommandProcessor.prototype.processDebugJSONRequest, look for
'references' command;
 - this leads to DebugCommandProcessor.prototype.referencesRequest_;
 - it calls ObjectMirror.prototype.referencedBy;
 - it delegates to the DebugReferencedBy native implementation,
located at runtime.cc with full name 'Runtime_DebugReferencedBy';
 - and the real work is done by the module-private function
DebugReferencedBy, in the same file.

On Mon, May 9, 2011 at 10:09, Charles Lowell <[email protected]> wrote:
> Mikhail,
>
> Thanks for the tips. This is exactly the type of functionality that
> I'm looking for. As far as I can tell, the d8 shell uses the JSON
> protocol to debug a remote process. I played around with this
> approach, but ran into a few challenges. While I know which object is
> hanging around, it isn't actually referenced by any JavaScript scope,
> so I can't use normal debugger commands to find out the object_id. How
> does one get the id?
>
>
> Second, I tried tracing the implementation of the references command,
> so that I could just get the information in-process via C++, but I
> didn't have any luck. Can someone point me in the right direction?
>
> Any help greatly appreciated.
>
> cheers,
> Charles
>
>
> On May 3, 2:46 pm, Mikhail Naganov <[email protected]> wrote:
>> Hi Charles,
>>
>> D8 has support for finding backreferences, you can learn how it's
>> implemented. Consider this sample D8 session:
>>
>> $ scons d8
>> $ ./d8 --debugger
>> V8 version 3.3.3 (candidate) [console: dumb]
>> JavaScript debugger enabled
>> d8> var a = {}
>> d8> function B(x) { this.x = x }
>> d8> var b = new B(a)
>> d8> debugger
>> break in [anonymous](), (d8) line 1 column 1
>> debugger
>> ^
>> dbg> dir a
>> #8#, type: object, constructor #9#, __proto__ #4#, 0 properties.
>>
>> dbg> references #8#
>> found 2 objects
>> #37#, type: object, constructor #39#, __proto__ #3#, 45 properties.
>> #38#, type: object, constructor #70#, __proto__ #80#, 1 properties.
>>
>> dbg> dir #38#
>> #38#, type: object, constructor #70#, __proto__ #80#, 1 properties.
>>   x: object #8#
>>
>> dbg> dir #70#
>> #70#, type: object, constructor #10#, __proto__ #11#, 5 properties.
>>   arguments: null #5#
>>   length: number #14#
>>   name: string #179#
>>   prototype: object #80#
>>   caller: null #5#
>>
>> dbg> dir #179#
>> type: string, "B"
>>
>>
>>
>>
>>
>>
>>
>> On Mon, May 2, 2011 at 23:38, Charles Lowell <[email protected]> 
>> wrote:
>> > Hi,
>>
>> > Is there an easy facility for finding out how many strong references a
>> > particular object has, and from which objects they originate? I've got
>> > a memory leak caused by a WeakReferenceCallback that never gets
>> > invoked. I presume this is because something, somewhere is holding a
>> > reference to it, but I'm having difficulty pinning down who or what
>> > that somebody is.
>>
>> > I've exhausted the possibilities reasoning about it, and so I'm
>> > looking for some way to just get empirical data. Thoughts?
>>
>> > cheers,
>> > Charles
>>
>> > --
>> > v8-users mailing list
>> > [email protected]
>> >http://groups.google.com/group/v8-users
>
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
>

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to