I tried to send an email to my own account using a laptop.
On my iPad the Mail application is completely out of memory, not in background... and magically still show the badge for the new mail just sent.
Does anyone have the idea on how this is programmatically implemented?
Quick response : Apple can do whatever they want.
Long response : the Mail app is running. You can use apps like iStat that will list you all the running processes. The MobileMail process is always running, whatever I do. If I kill the Mail app in the multitasking bar, it will be in fact killed, but will be relaunched immediately. You obviously can't do that as a 3rd party developer. Apple can do whatever they want.
And that's the case with old devices on pre-multitasking OS/ability the MobileMail process is always running.
It uses the iOS notification system, which doesn't require the application to be running. See Apples tutorial for the nitty gritty.