This is not really a
JDBC question. While your example uses a JDBC-created object, the same theory applies to all created objects.
Java is a "garbage collecting" language; the memory space of any object that no longer has any "live" references
may at any time be freed. This is managed by one or more threads running concurrently with your application and happens automatically from time to time. The garbage collector also automatically performs some compaction.
When a new object is being created and there isn't sufficient free memory on the heap, the garbage collector will first attempt to reap any dead objects, and if that fails will attempt to expand the heap - up to the maximum specified by the startup parameters on the java process (which may be a default value), and if that fails, will throw a fatal OutOfMemory exception.
Here's a nice introduction:
http://www.javaworld.com/javaworld/jw-08-1996/jw-08-gc.html
While there's lots and lots of things for Java gurus to know about garbage collection, at your current level I'd say:
1. don't keep unnecessary references to objects
2. make sure you explicitly close the JDBC resources you open or use a resource pool; in particular, if you expect to use JDBC on a real-world application in a concurrent use environment (such as a web application) you MUST know about connection pooling, whether you use it or not...
3. don't try to outsmart the garbage collector; that's a great way to really screw things up, until you're a real uber-guru
4. if you have any more questions about Java memory management, please move to a more appropriate forum