About object Finalize callback

60 views
Skip to first unread message

wenbin wang

unread,
Jan 6, 2010, 9:34:57 PM1/6/10
to google-gadgets...@googlegroups.com
When a object in javscript file like "SecondHand" does exist, an object will be constructed.
But when the object destructed,
or when the finalize callback is called?
Please tell me the detail about that in js_script_context.cc.
Thanks very much.

James Su

unread,
Jan 6, 2010, 9:53:35 PM1/6/10
to google-gadgets...@googlegroups.com
The javascript object will be garbage collected if it's not used anymore.

Regards
James Su

2010/1/7 wenbin wang <wbwan...@gmail.com>
Thanks very much.

--
You received this message because you are subscribed to the Google Groups "google-gadgets-for-linux-user" group.
To post to this group, send email to google-gadgets...@googlegroups.com.
To unsubscribe from this group, send email to google-gadgets-for-l...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-gadgets-for-linux-user?hl=en.


wbwang1985

unread,
Jan 6, 2010, 10:09:37 PM1/6/10
to google-gadgets-for-linux-user
But I can't see Finalizecallback called in debug information, 
in which function some release work must be done.
 
So can you tell me when Finalizecallback be called?
 
2010-01-07

wbwang1985

发件人: James Su
发送时间: 2010-01-07  10:53:59
收件人: google-gadgets-for-linux-user
抄送:
主题: Re: [ggl-user] About object Finalize callback

James Su

unread,
Jan 6, 2010, 10:12:14 PM1/6/10
to google-gadgets...@googlegroups.com


2010/1/7 wbwang1985 <wbwan...@gmail.com>

But I can't see Finalizecallback called in debug information, 
in which function some release work must be done.
 
So can you tell me when Finalizecallback be called?
Which function in which file?

wenbin wang

unread,
Jan 6, 2010, 10:32:15 PM1/6/10
to google-gadgets...@googlegroups.com
FinalizeCallback in js_script_context.cc.\
Thanks.

James Su

unread,
Jan 6, 2010, 11:03:12 PM1/6/10
to google-gadgets...@googlegroups.com
Do you mean extensions/webkit_script_runtime/js_script_context.cc? You may refer to this document for details. In short, this will be called when the object is prepared for garbage collection. Please search on Google if you want to know what is garbage collection and when it will occur.

wenbin wang

unread,
Jan 6, 2010, 11:14:33 PM1/6/10
to google-gadgets...@googlegroups.com
Yes. This will be called when the object is prepared for garbage collection, but it will not be called during the program running.  It causes the memory leak until memory is exhausted.
If you can tell me when FinalizeCallback called,  I will be very grateful about that! Thanks.

Xianzhu Wang

unread,
Jan 6, 2010, 11:23:01 PM1/6/10
to google-gadgets...@googlegroups.com
"SecondHand" is a JS wrapper of a native object (an ImageElement
object). The wrapper is created when it is first accessed, and will
have the same life time as the backed native object. This won't cause
memory-leak because this is not accumulative.

2010/1/7 wenbin wang <wbwan...@gmail.com>:


> Yes. This will be called when the object is prepared for garbage collection,
> but it will not be called during the program running. It causes the memory
> leak until memory is exhausted.
> If you can tell me when FinalizeCallback called, I will be very grateful
> about that! Thanks.
>

> 2010/1/7 James Su <jame...@gmail.com>


>>
>> Do you mean extensions/webkit_script_runtime/js_script_context.cc? You may
>> refer to this document for details. In short, this will be called when the
>> object is prepared for garbage collection. Please search on Google if you
>> want to know what is garbage collection and when it will occur.
>> Regards
>> James Su
>>
>> 2010/1/7 wenbin wang <wbwan...@gmail.com>
>>>
>>> FinalizeCallback in js_script_context.cc.\
>>> Thanks.
>>>

>>> 2010/1/7 James Su <jame...@gmail.com>

James Su

unread,
Jan 6, 2010, 11:22:42 PM1/6/10
to google-gadgets...@googlegroups.com
It's must be a bug if it's not called at all. Please tell us how did you produce this problem.

wbwang1985

unread,
Jan 7, 2010, 12:30:18 AM1/7/10
to google-gadgets-for-linux-user
But when the backed native object is destructed, how the wrapper be telled and destructs itself ?
Thanks very much.
 
 
 
2010-01-07

wbwang1985

发件人: Xianzhu Wang
发送时间: 2010-01-07  12:23:07
收件人: google-gadgets-for-linux-user
抄送:
主题: Re: Re: [ggl-user] About object Finalize callback

wenbin wang

unread,
Jan 7, 2010, 12:44:05 AM1/7/10
to google-gadgets-for-linux-user
The map of wrapper is accumulated.

2010/1/7 wbwang1985 <wbwan...@gmail.com>
But when the backed native object is destructed, how the wrapper be telled and destructs itself ?
Thanks very much.
 
 
 
2010-01-07

wbwang1985

发件人: Xianzhu Wang
发送时间: 2010-01-07  12:23:07
收件人: google-gadgets-for-linux-user
抄送:
主题: Re: Re: [ggl-user] About object Finalize callback
"SecondHand" is a JS wrapper of a native object (an ImageElement
object). The wrapper is created when it is first accessed, and will
have the same life time as the backed native object. This won't cause
memory-leak because this is not accumulative.
2010/1/7 wenbin wang <wbwan...@gmail.com>:
> Yes. This will be called when the object is prepared for garbage collection,
> but it will not be called during the program running.  It causes the memory
> leak until memory is exhausted.
> If you can tell me when FinalizeCallback called,  I will be very grateful
> about that! Thanks.
>

Xianzhu Wang

unread,
Jan 7, 2010, 1:14:19 AM1/7/10
to google-gadgets...@googlegroups.com
The native objects are reference counted. The reference (which was
added when the wrapper is created) to the wrapper will be removed when
the native object's reference count reaches 0, and the wrapper will be
removed from the map. Then during GC, the wrapper will be finalized if
there is no other reference from live JS objects to the wrapper.

2010/1/7 wenbin wang <wbwan...@gmail.com>:


> The map of wrapper is accumulated.
>
> 2010/1/7 wbwang1985 <wbwan...@gmail.com>
>>
>> But when the backed native object is destructed, how the wrapper be telled
>> and destructs itself ?
>> Thanks very much.
>>
>>
>>
>> 2010-01-07
>> ________________________________
>> wbwang1985
>> ________________________________
>> 发件人: Xianzhu Wang
>> 发送时间: 2010-01-07 12:23:07
>> 收件人: google-gadgets-for-linux-user
>> 抄送:
>> 主题: Re: Re: [ggl-user] About object Finalize callback
>> "SecondHand" is a JS wrapper of a native object (an ImageElement
>> object). The wrapper is created when it is first accessed, and will
>> have the same life time as the backed native object. This won't cause
>> memory-leak because this is not accumulative.
>> 2010/1/7 wenbin wang <wbwan...@gmail.com>:
>>
>> > > Yes. This will be called when the object is prepared for garbage collection,
>>
>> > > but it will not be called during the program running. It causes the memory
>> > leak until memory is exhausted.
>>
>> > > If you can tell me when FinalizeCallback called, I will be very grateful
>> > about that! Thanks.
>> >

>> > 2010/1/7 James Su <jame...@gmail.com>


>> >>
>>
>> >> >> Do you mean extensions/webkit_script_runtime/js_script_context.cc? You may
>>
>> >> >> refer to this document for details. In short, this will be called when the
>>
>> >> >> object is prepared for garbage collection. Please search on Google if you
>> >> want to know what is garbage collection and when it will occur.
>> >> Regards
>> >> James Su
>> >>
>> >> 2010/1/7 wenbin wang <wbwan...@gmail.com>
>> >>>
>> >>> FinalizeCallback in js_script_context.cc.\
>> >>> Thanks.
>> >>>

>> >>> 2010/1/7 James Su <jame...@gmail.com>

Xianzhu Wang

unread,
Jan 7, 2010, 1:23:02 AM1/7/10
to google-gadgets...@googlegroups.com
Please let us know if you have seen actual memory leaks. Thanks!

2010/1/7 Xianzhu Wang <phni...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages