If you use std.testing.allocator, the test runner will detect memory leaks and print stack traces. But memory is not the only resource. You can leak in other ways:
Call openFile, but never call File.close
Call process.Child.spawn, but never call kill or wait
Call Thread.spawn, but never call join or detach
Call myUserCodeStart, but never call myUserCodeEnd
Does Zig have any way to sanitize for these kinds of leaks?
I think this might make it so that we can do similar detection, for some of those other resources:
But the last one seems like it would require some sort of custom validation tooling, or adding support for validation, unless you also invent some sort of interface convention for your myUserCodeStart functions.
With new Io here how can this resource leak detection be achieved? I think my #1 bug is forgetting to close files, I only find out by reaching fd limit!
If I had to directly ask, is there a “DebugAllocator” like interface for Io yet? But I presume there isn’t from searching the std, so might there be a way to wrap an Io, calling the inner vtable.dirOpenFile/vtable.fileClose with an fd tracker?
I’ve seen tutorials on using the new Io but not much written on creating Io, what exactly is needed when filling out it’s vtable, is there more than just the vtable to be aware of? That could be it’s own topic/post though.
Thanks for the mention @Sze! Thought this looked interesting and added support in the newest release. Marionette now supports this for simulated I/O in v0.7.0
@gert For the missing File.close case, you can run your code with Marionette’s std.Io backend and enable .check_resources = true in expectSimPass or runSimCase. After a successful scenario and app cleanup, it checks for open simulated file/directory handles, listeners, and client/accepted sockets.
There’s also try sim.control.checkResources() for explicit checkpoints. Usage is documented here.