From 9cb378bb6b29fe61a52ed9a7edc81006ea809100 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 11 Nov 2021 17:38:45 +0200 Subject: [PATCH] examples: reduce the memory usage of the clock example, without -autofree & -gc boehm --- examples/clock/clock.v | 6 ++++-- vlib/gg/gg.v | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/clock/clock.v b/examples/clock/clock.v index 61e4430e4a..b111850f79 100644 --- a/examples/clock/clock.v +++ b/examples/clock/clock.v @@ -88,11 +88,12 @@ fn on_frame(mut app App) { } // Rotate a polygon round the centerpoint +[manualfree] fn draw_convex_poly_rotate(mut ctx gg.Context, dpi_scale f32, points []f32, c gx.Color, angle f32) { sa := math.sin(math.pi * angle / 180.0) ca := math.cos(math.pi * angle / 180.0) - mut rotated_points := []f32{} + mut rotated_points := []f32{cap: points.len} for i := 0; i < points.len / 2; i++ { x := points[2 * i] y := points[2 * i + 1] @@ -102,6 +103,7 @@ fn draw_convex_poly_rotate(mut ctx gg.Context, dpi_scale f32, points []f32, c gx rotated_points << (yn + center) * dpi_scale } ctx.draw_convex_poly(rotated_points, c) + unsafe { rotated_points.free() } } fn (mut app App) resize() { @@ -133,7 +135,7 @@ fn on_event(e &gg.Event, mut app App) { .q { println('Good bye.') // do we need to free anything here? - exit(0) + app.gg.quit() } else {} } diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index 408402ffe6..1959f39833 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -237,6 +237,7 @@ fn gg_cleanup_fn(user_data voidptr) { if g.config.cleanup_fn != voidptr(0) { g.config.cleanup_fn(g.config.user_data) } + gfx.shutdown() } fn gg_fail_fn(msg &char, user_data voidptr) {