[geary/bug/728002-webkit2: 52/140] Update Javascript memory management a bit.



commit 503ca3b47887efb0d4f29e858cef14baf769329a
Author: Michael James Gratton <mike vee net>
Date:   Sun Jan 1 15:18:54 2017 +1100

    Update Javascript memory management a bit.
    
    * bindings/vapi/javascriptcore-4.0.vapi: Don't pretend JS.String will
      be unreff'ed by vala, it wont. Add JS.GlobalContext.retain, in case it
      wants to be used.
    
    * src/client/components/client-web-view.vala
      (ClientWebView::ClientWebView): JavascriptResult instances are unref'ed
      when unowned.

 bindings/vapi/javascriptcore-4.0.vapi      |   12 ++++++++++--
 src/client/components/client-web-view.vala |   10 +++++++++-
 2 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/bindings/vapi/javascriptcore-4.0.vapi b/bindings/vapi/javascriptcore-4.0.vapi
index c47d845..f31478e 100644
--- a/bindings/vapi/javascriptcore-4.0.vapi
+++ b/bindings/vapi/javascriptcore-4.0.vapi
@@ -5,7 +5,11 @@
  * (version 2.1 or later). See the COPYING file in this distribution.
  */
 
-[CCode (cprefix = "JS", gir_namespace = "JavaScriptCore", gir_version = "4.0", lower_case_cprefix = "JS_", 
cheader_filename = "JavaScriptCore/JavaScript.h")]
+[CCode (cprefix = "JS",
+        gir_namespace = "JavaScriptCore",
+        gir_version = "4.0",
+        lower_case_cprefix = "JS_",
+        cheader_filename = "JavaScriptCore/JavaScript.h")]
 namespace JS {
 
        [CCode (cname = "JSContextRef")]
@@ -31,8 +35,12 @@ namespace JS {
     [SimpleType]
        public struct GlobalContext : Context {
 
+        [CCode (cname = "JSGlobalContextRetain")]
+        public bool retain();
+
         [CCode (cname = "JSGlobalContextRelease")]
         public bool release();
+
        }
 
        [CCode (cname = "JSType", has_type_id = false)]
@@ -120,7 +128,7 @@ namespace JS {
 
        }
 
-       [CCode (cname = "JSStringRef", ref_function = "JSStringRetain", unref_function = "JSStringRelease")]
+       [CCode (cname = "JSStringRef")]
     [SimpleType]
        public struct String {
 
diff --git a/src/client/components/client-web-view.vala b/src/client/components/client-web-view.vala
index a0564c5..2e79771 100644
--- a/src/client/components/client-web-view.vala
+++ b/src/client/components/client-web-view.vala
@@ -210,11 +210,17 @@ public class ClientWebView : WebKit.WebView {
                     queue_resize();
                 } catch (Geary.JS.Error err) {
                     debug("Could not get preferred height: %s", err.message);
+                } finally {
+                    result.unref();
                 }
             });
         content_manager.script_message_received[REMOTE_IMAGE_LOAD_BLOCKED_MESSAGE].connect(
             (result) => {
-                remote_image_load_blocked();
+                try {
+                    remote_image_load_blocked();
+                } finally {
+                    result.unref();
+                }
             });
         content_manager.script_message_received[SELECTION_CHANGED_MESSAGE].connect(
             (result) => {
@@ -222,6 +228,8 @@ public class ClientWebView : WebKit.WebView {
                     selection_changed(WebKitUtil.to_bool(result));
                 } catch (Geary.JS.Error err) {
                     debug("Could not get selection content: %s", err.message);
+                } finally {
+                    result.unref();
                 }
             });
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]