For testing purposes consider https://github.com/mvz/memory_test_fix plug-in. It's usage as easy as to update database.yml
and to run
rails plugin install git://github.com/mvz/memory_test_fix.git
You may try also install memory_test_fix gem, but it's from different git branch and does not support Rails 3.
The gem helped me to reduce test cases execution time from 25 seconds to 19. On the other hand, it introduces 2 second overhead on database schema initialisation (and i don't have that much of them). So on small sets of tests it's not worth bothering.
Solution from Jason Stewart's answer is basically the same. And I used it instead of plugin, because it was easier to combine it with Spork plug-in.