In general that isn’t easy. If there is reason to worry I normally create a loop and run it for a while, possibly using some memory leak detection tool such as valgrind
or heaptrack
.
For blob references it is typically safe to try and interact with them after the close and expect an existence_error. Some (older) code tests to represent pointers as Prolog integers and interacting with them after freeing can easily cause a crash. In newer code such reference are only used if it concerns stuff the user should never see.
Still, the fact that interacting with a closed stream produces an existing error doesn’t verify all associated memory and OS resources are properly reclaimed. The above loop is (I think) the only sensible way to test that.