void gf_js_delete_context(JSContext *ctx)
{
	if (!js_rt) return;

	gf_js_call_gc(ctx);

	gf_mx_p(js_rt->mx);
	gf_list_del_item(js_rt->allocated_contexts, ctx);
	JS_FreeContext(ctx);
	gf_mx_v(js_rt->mx);
	gf_js_call_gc(NULL);

	js_rt->nb_inst --;
	if (js_rt->nb_inst == 0) {
		//persistent context, do not delete runtime but perform GC
		if (gf_opts_get_bool("temp", "peristent-jsrt")) {
			JS_RunGC(js_rt->js_runtime);
			return;
		}

		qjs_uninit_runtime_libc(js_rt->js_runtime);
		JS_FreeRuntime(js_rt->js_runtime);
		gf_list_del(js_rt->allocated_contexts);
		gf_mx_del(js_rt->mx);
		gf_free(js_rt);
		js_rt = NULL;
	}
}
void gf_js_delete_context(JSContext *ctx)
{
	if (!js_rt) return;

	gf_js_call_gc(ctx);

	gf_mx_p(js_rt->mx);
	gf_list_del_item(js_rt->allocated_contexts, ctx);
	JS_FreeContext(ctx);
	gf_mx_v(js_rt->mx);
	gf_js_call_gc(NULL);

	js_rt->nb_inst --;
	if (js_rt->nb_inst == 0) {
		 
		if (gf_opts_get_bool("temp", "peristent-jsrt")) {
			JS_RunGC(js_rt->js_runtime);
			return;
		}

		qjs_uninit_runtime_libc(js_rt->js_runtime);
		JS_FreeRuntime(js_rt->js_runtime);
		gf_list_del(js_rt->allocated_contexts);
		gf_mx_del(js_rt->mx);
		gf_free(js_rt);
		js_rt = NULL;
	}
}