See: http://www.geany.org/manual/reference/document_8h.html#aa14a04c6596cd3261b32...
Real-world example when clicking a Messages item: https://github.com/geany/geany/commit/18181c2e9043add8b13c1fc94c66db2ca5b885...
Code that uses doc->is_valid or DOC_VALID() outside of iterating documents_array probably should be using document_find_by_id() instead, because closed document pointers only stay invalid until another document needs to be opened.
Regards, Nick