[gjs] all: schedule a full GC check after executing JS code



commit 5719e781e95e8f693db616ef0f7b77cbc730186d
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Feb 27 14:05:41 2014 -0800

    all: schedule a full GC check after executing JS code
    
    After we return from JS::Call* or JS::Evaluate*, schedule a GC check
    for the next idle iteration, to prevent memory consumption skyrocketing.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725099

 gi/function.cpp     |    3 +++
 gi/repo.cpp         |    2 ++
 gjs/jsapi-util.cpp  |    5 +++++
 modules/console.cpp |    3 +++
 4 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 91f3c12..a96b681 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -32,6 +32,7 @@
 #include "gerror.h"
 #include <gjs/gjs-module.h>
 #include <gjs/compat.h>
+#include <gjs/jsapi-private.h>
 
 #include <util/log.h>
 
@@ -395,6 +396,8 @@ out:
     }
 
     gjs_callback_trampoline_unref(trampoline);
+    gjs_schedule_gc_if_needed(context);
+
     JS_EndRequest(context);
 }
 
diff --git a/gi/repo.cpp b/gi/repo.cpp
index ab8f38e..8037d5f 100644
--- a/gi/repo.cpp
+++ b/gi/repo.cpp
@@ -38,6 +38,7 @@
 #include "gerror.h"
 
 #include <gjs/compat.h>
+#include <gjs/jsapi-private.h>
 
 #include <util/log.h>
 #include <util/misc.h>
@@ -148,6 +149,7 @@ resolve_namespace_object(JSContext  *context,
               "Defined namespace '%s' %p in GIRepository %p", ns_name, gi_namespace, repo_obj);
 
     ret = JS_TRUE;
+    gjs_schedule_gc_if_needed(context);
 
  out:
     if (gi_namespace)
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 53772a8..b360cf2 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -740,6 +740,9 @@ gjs_call_function_value(JSContext      *context,
     result = JS_CallFunctionValue(context, obj, fval,
                                   argc, argv, rval);
 
+    if (result)
+        gjs_schedule_gc_if_needed(context);
+
     JS_EndRequest(context);
     return result;
 }
@@ -1330,6 +1333,8 @@ gjs_eval_with_scope(JSContext    *context,
     if (!JS::Evaluate(context, rootedObj, options, script, script_len, &retval))
         return JS_FALSE;
 
+    gjs_schedule_gc_if_needed(context);
+
     if (JS_IsExceptionPending(context)) {
         g_warning("EvaluateScript returned JS_TRUE but exception was pending; "
                   "did somebody call gjs_throw() without returning JS_FALSE?");
diff --git a/modules/console.cpp b/modules/console.cpp
index 3ea0c64..b3d71ff 100644
--- a/modules/console.cpp
+++ b/modules/console.cpp
@@ -53,6 +53,7 @@
 #include <glib/gprintf.h>
 #include <gjs/gjs-module.h>
 #include <gjs/compat.h>
+#include <gjs/jsapi-private.h>
 
 #include "console.h"
 
@@ -198,6 +199,8 @@ gjs_console_interact(JSContext *context,
         js::RootedObject rootedObj(context, object);
         JS::Evaluate(context, rootedObj, options, buffer->str, buffer->len,  &result);
 
+        gjs_schedule_gc_if_needed(context);
+
         if (JS_GetPendingException(context, &result)) {
             str = JS_ValueToString(context, result);
             JS_ClearPendingException(context);


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