After recently getting a bargain on a no-name 256MB USB key drive I wanted to store an encrypted password-protected disk image on it. However after playing around with Disk Utility for a while, I discovered that although a 'sparse' disk image sounded like what I wanted, it actually wasn't! The problem with sparse disk images is that although they aren't fixed in size and grow as you add more stuff to them (which is what I wanted), when you delete the same stuff they do not automatically shrink! Technically this is understandable since the 'deleted' data hasn't been zeroed and is actually still on the 'disk', however it wasn't what I was hoping for.
So after much fruitless searching, I appended a question onto this existing Apple discussion in the hope for an answer. However after re-reading the discussion and having a look at the hdiutil man pages I eventually managed to refine my search enough to turn up an article on MacOSXHints which had exactly the solution I needed!
The answer is simple! Simply fire up the terminal, and type:
hdiutil compact (with a space at the end)
and then drag and drop your sparse disk image file into the terminal window. Note that you need to type a space after the word 'compact', before you drag the image icon to the terminal window.
Depending on the size of your sparse image the process will take a few seconds to a few minutes. Get info should now reveal that the image file no longer 'remembers' the size of the deleted files.
Note: when specifying the size of an encrypted sparse image in Disk Utility you are specifying the maximum size.