memory management is controled by sql server
when it requires it gets memory by deleting some plans from the cache
you can still release memory from plan cache by doing
dbcc freeproccache
but the case you described above is that both the queries are the same.
second one is best practise.