After you finish collecting data for a query, call the PdhCloseQuery function to close the query and release all allocated system resources. PdhCloseQuery closes all counter handles associated with the query.