Discourse keeps track of references to uploaded files. When no posts remain that include a link or reference to the upload, the file is automatically moved to a tombstone area by an automated background job. Another background job periodically cleans out the tombstone area, permanently deleting any files that have been tombstoned for at least one month.
The URL you see in the
<img> tag contains the uploaded file’s SHA1 hash. If two uploaded files have the same hashsum (which for all intents and purposes means that they are identical), they will have the same URL and will be stored in the same file on the server’s harddisk, and this file will only be deleted once all references to it have been removed from posts, regardless of whether an
<img> tag was copied or the same file was uploaded a second time.