feat: add System.gc() method and replace test's Api.gc() with it

Add a new `System.gc()` primitive that calls `wrenCollectGarbage` to allow
scripts to trigger garbage collection. Document the method in the core
System page. Remove the test-only `Api.gc()` foreign method and update
the foreign_class test to use `System.gc()` instead.
This commit is contained in:
Bob Nystrom
2015-10-24 17:56:27 +00:00
parent c9a7dba0c1
commit 498d1af8d0
4 changed files with 20 additions and 15 deletions
-6
View File
@@ -5,11 +5,6 @@
static int finalized = 0;
static void apiGC(WrenVM* vm)
{
wrenCollectGarbage(vm);
}
static void apiFinalized(WrenVM* vm)
{
wrenReturnDouble(vm, finalized);
@@ -84,7 +79,6 @@ static void resourceFinalize(WrenVM* vm)
WrenForeignMethodFn foreignClassBindMethod(const char* signature)
{
if (strcmp(signature, "static Api.gc()") == 0) return apiGC;
if (strcmp(signature, "static Api.finalized") == 0) return apiFinalized;
if (strcmp(signature, "Counter.increment(_)") == 0) return counterIncrement;
if (strcmp(signature, "Counter.value") == 0) return counterValue;
+3 -4
View File
@@ -1,5 +1,4 @@
class Api {
foreign static gc()
foreign static finalized
}
@@ -64,15 +63,15 @@ var resources = [
Resource.new()
]
Api.gc()
System.gc()
System.print(Api.finalized) // expect: 0
resources.removeAt(-1)
Api.gc()
System.gc()
System.print(Api.finalized) // expect: 1
resources.clear()
Api.gc()
System.gc()
System.print(Api.finalized) // expect: 3