2

I have experienced the following paradox many times, and I don't understand how it happens.

I open a big music/video file (say 100 MB), and when it starts playing, I delete it (permanently). In spite of this, the media player will be able to play the whole thing.
I guess it doesn't buffer the whole file at the beginning, because

  • memory usage by the process is only 15 MB
  • and that's not what media players do anyway.

So how does this happen?

1 Answer 1

6

The exact details depend on your system, but the basic idea is that the underlying filesystem won't pull the rug out from under an open file. It deletes it from everywhere you can see it, but it won't actually clean up the blocks on disk (nor some representation of the directory structures that point to the file) until you close it.

On Unix systems this is common: most unix filesystems won't blow away an inode until the last open filehandle is closed.

On Windows, it seems that if the opening process specifies 'FILE_SHARE_DELETE' to the CreateFile call (which a well behaved program should do), then the filesystem driver processes the deletion, but the open files can still access it. Once the last open HANDLE to the file is closed, then the file is cleaned up by the file system driver.

3
  • But I use Windows... Wether I can delete it or not seems to depend on the file type.
    – Dave
    Feb 11, 2013 at 20:29
  • 2
    @Dave - see my revision - Windows has a way that (well behaved) programs can cause this to work correctly. Feb 11, 2013 at 20:37
  • agreed, this is a side effect of thread/multi-process resource share. Feb 11, 2013 at 21:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .