-- 10: RAM-only owned structs (Image, AutomationEventList, FilePathList, Wave) -- release at GC time and Image churn does not grow RSS. local M = dofile("tests/helpers.lua") local R = M.load() M.reset() local b = M.snapshot() do local img = R.GenImageColor(4, 4, R.RED) M.ok(img.data ~= nil, "image allocated") end M.gc(2) do local list = R.LoadAutomationEventList(nil) M.ok(list.events ~= nil, "empty automation event list allocated") end M.gc(2) do local files = R.LoadDirectoryFiles(".") M.ok(files.paths ~= nil, "directory file list allocated") M.ok(files.count > 0, "directory file list is non-empty") end M.gc(2) do local data, size = M.wav_bytes(441) local wave = R.LoadWaveFromMemory(".wav", data, size) M.ok(wave.data ~= nil, "wave allocated") end M.gc(2) M.ok(M.delta(b, "released") >= 4, string.format("expected >=4 released RAM resources, got %d", M.delta(b, "released"))) M.eq(M.delta(b, "errors"), 0, "no finalizer errors") -- 200 batches of 128x128 images: a leaked 64 kB image per batch would add -- ~12.8 MB. Allow generous allocator noise, but not a real leak. local rss0 = M.rss_kb() for i = 1, 200 do local im = R.GenImageColor(128, 128, R.RED) M.ok(im.data ~= nil, "batch image " .. i .. " allocated") M.gc(1) end M.gc(3) local rss1 = M.rss_kb() if rss0 > 0 and not M.under_valgrind() then local growth_kb = rss1 - rss0 M.ok(growth_kb < 8 * 1024, string.format( "rss grew %d kB across 200 image batches (%d -> %d kB)", growth_kb, rss0, rss1)) end print("ok 10_ram")