diff --git a/source/ona/heap.zig b/source/ona/heap.zig index 2b250f4..2c6cecf 100644 --- a/source/ona/heap.zig +++ b/source/ona/heap.zig @@ -7,7 +7,7 @@ const std = @import("std"); /// /// /// -const stack_trace_frame_size = if (std.debug.sys_can_stack_trace) 4 else 0; +const stack_trace_frame_size = if (std.debug.sys_can_stack_trace) 16 else 0; /// /// @@ -166,7 +166,8 @@ pub const allocator = coral.io.Allocator.bind(Context, &context, struct { pub fn trace_allocations() void { var current_allocation_info = context.allocation_info_head; - while (current_allocation_info) |allocation_info| : (current_allocation_info = allocation_info) { + while (current_allocation_info) |allocation_info| : (current_allocation_info = allocation_info.next_info) { + std.debug.print("{d} byte leak detected", .{allocation_info.size}); std.debug.dumpStackTrace(allocation_info.stack_trace); } } diff --git a/source/ona/kym/Environment.zig b/source/ona/kym/Environment.zig index 2ea0782..41e9920 100644 --- a/source/ona/kym/Environment.zig +++ b/source/ona/kym/Environment.zig @@ -185,8 +185,17 @@ pub fn check(self: *Self, condition: bool, failure_message: []const u8) !void { } pub fn deinit(self: *Self) void { + var global_data = self.heap.fetch(self.global_object); + + if (global_data.release(self)) { + self.heap.remove(self.global_object); + } else { + self.heap.assign(self.global_object, global_data); + } + self.values.deinit(self.allocator); self.calls.deinit(self.allocator); + self.heap.deinit(self.allocator); } pub fn discard(self: *Self, val: types.Val) void { diff --git a/source/ona/ona.zig b/source/ona/ona.zig index 81d14ea..72ecb56 100755 --- a/source/ona/ona.zig +++ b/source/ona/ona.zig @@ -55,7 +55,9 @@ const AppManifest = struct { } }; -pub fn run_app(base_file_system: file.System) void { +pub fn run_app(_: file.System) void { + defer heap.trace_allocations(); + const Logger = struct { const Self = @This(); @@ -74,12 +76,12 @@ pub fn run_app(base_file_system: file.System) void { defer script_environment.deinit(); - const app_file_name = "app.ona"; + // const app_file_name = "app.ona"; var app_manifest = AppManifest{}; - app_manifest.load_script(&script_environment, base_file_system, app_file_name) catch { - return ext.SDL_LogError(ext.SDL_LOG_CATEGORY_APPLICATION, "failed to load %s\n", app_file_name); - }; + // app_manifest.load_script(&script_environment, base_file_system, app_file_name) catch { + // return ext.SDL_LogError(ext.SDL_LOG_CATEGORY_APPLICATION, "failed to load %s\n", app_file_name); + // }; if (ext.SDL_Init(ext.SDL_INIT_EVERYTHING) != 0) { return ext.SDL_LogError(ext.SDL_LOG_CATEGORY_APPLICATION, "%s\n", ext.SDL_GetError()); @@ -135,6 +137,4 @@ pub fn run_app(base_file_system: file.System) void { ext.SDL_RenderPresent(renderer); } } - - heap.trace_allocations(); }