module
UI::NativeHandleTracker
Overview
Debug-only handle tracker that monitors NativeHandle lifetimes.
Compiled only when -Dui_debug is passed to the Crystal compiler.
In release builds, all tracker calls in NativeHandle are eliminated
at compile time via {% if flag?(:ui_debug) %} guards.
Usage
Build with debug tracking:
crystal build my_app.cr -Dui_debug
Dump leaks at shutdown:
at_exit do
UI::NativeHandleTracker.dump_leaks
end
How It Works
NativeHandle#initializecalls.registerto record the handle.NativeHandle#release!calls.unregisterto remove the handle.- At shutdown,
.dump_leaksreports any handles that were never released. - The tracker uses the pointer address as the key (cast to UInt64).
Defined in:
ui/native/handle_tracker.crClass Method Summary
- .clear : Nil
- .dump_leaks(io : IO = STDERR) : Nil
- .live_count : Int32
- .register(handle : NativeHandle) : Nil
- .unregister(handle : NativeHandle) : Nil