/* Some operating systems (e.g. Windows) don't permit a file to be deleted
         * while it is opened for read (e.g. by another process or thread).  So we
         * assume that when a delete fails it is because the file is open in another
         * process, and queue the file for subsequent deletion. */

        private void  DeleteSegments(System.Collections.ArrayList segments)
        {
            System.Collections.ArrayList deletable = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));

            DeleteFiles(ReadDeleteableFiles(), deletable); // try to delete deleteable

            for (int i = 0; i < segments.Count; i++)
            {
                SegmentReader reader = (SegmentReader)segments[i];
                if (reader.Directory() == this.directory)
                {
                    DeleteFiles(reader.Files(), deletable);
                }
                // try to delete our files
                else
                {
                    DeleteFiles(reader.Files(), reader.Directory()); // delete other files
                }
            }

            WriteDeleteableFiles(deletable); // note files we can't delete
        }