When using $template->create() to get a template (for example in the templates hook listener), if the template isn't preloaded it will generate a query to fetch the template (assuming the templates are not saved as files).
In this case, the query count in the footer seems not to include the above query into the total. When looking in the debug page, it does show the correct amount of queries.
The debug information is rendered before the PAGE_CONTAINER so if you're doing something after that, this is generally expected. Not ideal, but the query count/memory usage should be considered to be more of a general guide and the full debug page may provide slightly more accurate details.