Sql-server – FileStream files won’t deleted after records deleteion

filestreamsql server

I am working in sql server 2016 with Filestream attribute column.
I have a column with filestream attribute activated on it. when I insert a reacord in TSQL , the associated file is created in Filestream container folder which is correct. but the problem is that when I delete a row , the assoicated file in filestream container remains and won't be deleted. as far as I know this shouldn't happen and the file is completely related to its record, so why doesn't it delete?

Thank you

Best Answer

Unneeded filestream container files are physically deleted by a separate background garbage collection process. The files will eventually be deleted to reclaim the storage, just not in real time.

You can force garbage collection to occur immediately using sp_filestream_force_garbage_collection.