Skip to content

Instantly share code, notes, and snippets.

@perky
Created March 27, 2026 08:56
Show Gist options
  • Select an option

  • Save perky/b49606bd75a9180b15202b5756068cab to your computer and use it in GitHub Desktop.

Select an option

Save perky/b49606bd75a9180b15202b5756068cab to your computer and use it in GitHub Desktop.
gdzig memory leak example
// Registration omitted for brevity
const TestNode = struct {
base: *godot.class.RefCounted,
pub fn create(allocator: *Allocator) !*TestNode {
var self = try allocator.create(TestNode);
self.* = .{
.base = godot.class.RefCounted.init(),
};
self.base.setInstance(TestNode, self);
return self;
}
pub fn destroy(self: *TestNode, allocator: *Allocator) void {
self.base.destroy();
allocator.destroy(self);
}
pub fn fillArray(_: *TestNode, out_arr: godot.builtin.Array) void {
var out_arr_copy = out_arr.copy();
defer out_arr_copy.deinit();
for (0..1024) |i| {
var int: i64 = @intCast(i);
out_arr_copy.pushBack(.wrap(i64, &int));
}
}
pub fn makeArray(_: *TestNode) godot.builtin.Array {
var arr = godot.builtin.Array.init();
for (0..1024) |i| {
var int: i64 = @intCast(i);
arr.pushBack(.wrap(i64, &int));
}
return arr;
}
};
// In GDScript you have something like this
// var test_node = TestNode.new()
// func _process(_delta: float):
// var values = []
// test_node.fill_array(values)
// print(values.size())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment