What kind of query? Named queries optionally perform caching, which might explain your observations. (Though off by default.)
Also, are you looking at memory usage from within Ignition's gateway performance page? Or via your gateway's OS task manager? If the latter, then you should know that java doesn't give memory back to the OS.