Created
March 27, 2026 08:56
-
-
Save perky/b49606bd75a9180b15202b5756068cab to your computer and use it in GitHub Desktop.
gdzig memory leak example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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