Set the destroyed flag at the correct time and fix a the httpupload example to release all resources