Ok, thanks. In my case, I it does not delete it at all but at the same time I realized that the newMediaObject does not create the attachment post… it just uploads the file to the filesystem. Maybe that is the reason why it also does not delete it after. Do you believe it is a bug or is there something in my code that prevents creation of the attachment post?
Thanks. The caching solution sounds good to me. However, the old file does not seem to be deleted from the system for me. Is it supposed to get deleted instantaneously or all old files get deleted on a schedule (e.g. once per day)?