Skip to content

Commit 56c1d58

Browse files
committed
chore: Documentation updates
1 parent fd2bb79 commit 56c1d58

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ working, 🟨 - Partially working, ❌ - Not working)
1818
| Feature | Support | Note |
1919
| ------- | :-----: | ---- |
2020
| Dart as a Godot Extension Language | 🟨 | |
21-
| Dart Debugging Extension | | Attach to `http://127.0.0.1:5858` |
21+
| Dart Debugging (VS Code) | | See [Debugging](#debugging) |
2222
| Dart Available as a Scripting Language | 🟨 | Mostly usable in personal testing |
2323
| Hot Reload || Hot Reload button now included. |
2424
| Simplified Binding using build_runner | 🟨 | Early implementation |
@@ -267,13 +267,27 @@ position = pos;
267267
But in my opinion, this defeats the purpose of wrapping properties. Properties
268268
should mimic public member variables, and, when they can't, use methods instead.
269269

270+
# Debugging
271+
272+
Because of a change in the Dart SDK, you currently need to run the Dart Dev Service (DDS) in order to debug your game or Dart code in the Godot editor. To do so, with your game running, run the following in a terminal:
273+
274+
```
275+
dart development-service --vm-service-uri=http://127.0.0.1:5858
276+
```
277+
278+
I'm looking into ways to improve this experience in the long term.
279+
270280
# Performance
271281

272282
I have not measured the performance of this extension, partially because I know there is a lot of space for improvement in the
273283
embedding library itself, as well as in how the built in types are currently built.
274284

275285
Once I've performed an optimization pass on the library, I'll look into measuring its performance.
276286

287+
# Memory
288+
289+
See [Memory](docs/memory.md)
290+
277291
# More Info
278292

279293
This utilizes my custom built Dart shared library for embedding Dart, the source

docs/memory.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Memory
2+
3+
`RefCounted` objects in Godot need special handling in garbage collected languages like Dart.
4+
5+
Any `RefCounted` object that is refernced by Dart adds one to its reference count, and its Script Instance Binding or Extension Instance Binding holds a handle to the Dart version of the object. However, Dart needs to know if it can safely garbage collect this object and release its reference to the `RefCounted` object, otherwise Dart will hold it forever and the object will leak.
6+
7+
What Dart does is use the `referenced` callback of both Script Instance Bindings and Extension Instance Bindings to determine if it is the *only* reference to a `RefCounted`object. If it is, the Godot Dart engine converts its reference to the object to *weak*, which means that if no objects in Dart are referencing it, it can safely be garbage collected. If Dart is not the only reference, the Godot Dart engine changes its reference to *strong* so that even if no Dart objects are referencing the object, Dart doesn't accidentlly garbage collect a handle it needs to remain valid.
8+
9+
To help make sense of the logic, here's a diagram:
10+
11+
```mermaid
12+
flowchart TD
13+
X(tieDartToNative) --> A{Is RefCounted?}
14+
A -->|No| B(Hold String)
15+
A -->|Yes| C(Hold Weak) --> D(initRef) --> E{Is RefCount > 1?}
16+
E -->|Yes| F(Convert To Strong)
17+
Y(reference callback) --> R{Is Incrementing?}
18+
R -->|Yes| S{RefCount > 1?}
19+
S -->|Yes| T(Hold Strong)
20+
R -->|No| U{RefCount == 1?}
21+
U -->|Yes| V(Hold Weak)
22+
```

0 commit comments

Comments
 (0)