Jonathan Zdziarski, author of iPhone Open Application Development, has been working on a forensics toolkit for law enforcement that allows the recovery of personal data from the iPhone. Apparently, the inspiration for this came from a discovery that refurbished iPhones, straight from the Apple store, often times contained personal information on the reformatted filesystem. This includes things like photos, contacts, and even more personal information that might have been in an email.
Just as you would scrub a hard disk before selling your computer, you should take a few minutes to clean the data from your iPhone if you’re thinking of getting rid of it. Performing a normal restore just recreates the filesystem without completely scrubbing the drive’s data, so to really clean a device before getting rid of it, you’ll need to completely write over the disk. Jonathan has an article which walks you through a few simple steps to do just that. Writing over the entire disk takes quite a bit of time, so be prepared to let it sit for a couple of hours.