[webkit-gtk] Memory management for JavaScriptCore objects

Michael Gratton mike at vee.net
Sun Jan 1 16:47:23 PST 2017


Hey all,

As part of porting Geary to WK2 (I'm writing this from it now!) I have 
been developing a Vala VAPI[0] for JSC, so I can work with the JS 
objects returned by JavascriptResult and Frame directly from Vala, 
without dropping back to C. However since they are not GObjects and not 
ref counted, I need to get the momeory management right still.

I've been trying to work out when to use functions like 
JSGlobalContextRelease, JSStringRelease, and JSValueUnprotect, but 
haven't been able to find any useful documentation about it. Also, 
examples on the web seem to conflict: E.g. The WebKitGTK docs and 
Cookbook[1] uses JSStringRelease on a string copied from a JSValueRef, 
whereas others (e.g. [2]) suggest that JSStringRelease only needs to be 
used in certain instances, or that it needs to be used all the time. 
Any pointers to canonical docs and examples would be appreciated.

I assume I never need to release a JSGlobalContextRef obtained from 
JavascriptResult or Frame, since the web process will effectively 
retain it, but what about the others? Would it hurt to call 
JSGlobalContextRelease and JSStringRelease even if not needed? What 
about JSValueRefs?

Also, my assumption that JSC objects should be treated as Vala simple 
types, i.e. they should be passed as copies (not by reference), that's 
correct isn't it?

Cheers,
//Mike

[0] - 
<https://git.gnome.org/browse/geary/tree/bindings/vapi/javascriptcore-4.0.vapi?h=wip/728002-webkit2>
[1] - 
<https://wiki.gnome.org/Projects/WebKitGtk/ProgrammingGuide/Cookbook>
[2] - 
<http://parmanoir.com/Taming_JavascriptCore_within_and_without_WebView>

-- 
⊨ Michael Gratton, Percept Wrangler.
⚙ <http://mjog.vee.net/>




More information about the webkit-gtk mailing list