A context is freed after it is deleted and all outstanding references to it have been released.
There is one exception to this rule: if a context has been created but has not been set by calling FltSetXxxContext, it does not need to be deleted. It is freed when its reference count reaches zero. (See the code example in Releasing Contexts.)
When a minifilter driver registers its context types, each context definition can optionally include a context cleanup callback routine to be called before the context is freed. For more information, see PFLT_CONTEXT_CLEANUP_CALLBACK.