I have a function that create a backup of the app and download it in a zip file, with the datas in the databases, images, files, etc. For this i create a big temp file (using the Tempfile class) that send to browser with send_data, but when i delete it after send_data the download failed and its memory is not released.
send_file(zip_data.path, type: 'application/zip', filename: "#{model_name}.zip")
zip_data.unlink
Service class: http://pastebin.com/MskjP8d7
Controller method: http://pastebin.com/CV9Wr27h