aboutsummaryrefslogtreecommitdiff
path: root/GC.md
diff options
context:
space:
mode:
Diffstat (limited to 'GC.md')
-rw-r--r--GC.md25
1 files changed, 25 insertions, 0 deletions
diff --git a/GC.md b/GC.md
new file mode 100644
index 0000000..c7aac96
--- /dev/null
+++ b/GC.md
@@ -0,0 +1,25 @@
+# Region-based garbage collection
+Memory that is allocated should have metadata to which block (scope) it belongs to.
+When data is moved, the metadata should be updated to which block it belongs to.
+When a function is called and the function accesses a member owned by the callee, then the owner region of the member should
+be temporary changed to that function and then at the end of the scope, it should be reverted to the callee so the member is not
+freed. This would be a runtime borrow mechanism. However if the variable is passed to the function and not used after that, then it should be freed in
+the called function, or at the end of the parent scope (which could be a if/for scope). This would be a runtime move mechanism.
+
+```
+create_linked_list = fn() {
+ # Circular linked list!
+ a = { next: null }
+ b = { next: a }
+ c = { next: b }
+ a.next = c
+ return c
+}
+
+main = fn() {
+ linked_list = create_linked_list()
+ while(true) {
+ # ...
+ }
+}
+``` \ No newline at end of file