"The use of flash memory in SSDs means that they have a limited number of write cycles. When data is deleted from an SSD, the space it occupied is not immediately available for reuse. Instead, the drive's firmware marks the space as “invalid” and it is not overwritten until the trimming process is performed. This process helps prevent the disk from fragmenting and slowing down the disk.
Garbage collection is beneficial to the life of the SSD and its overall performance, while TRIM simply makes it better (sometimes the two terms are used interchangeably). Without this command, garbage collection would simply move all pages continuously, compacting partially filled blocks to keep the newly erased blocks available for programming - but this means that unnecessary pages would also be moved around, wasting time and increasing wear and tear on memory cells.
Since TRIM explicitly indicates which pages are now unnecessary, they can be left untouched during garbage collection and erased as needed.
The TRIM function is automatically issued by Windows when a file is finally deleted (i.e. removed from the Recycle Bin), but it does not happen instantly. It is added to a queue and processed when the SSD is ready for it.
However, this queue has a maximum size, and if it fills up, some of the TRIM requests will be canceled. By default, Windows plans to reissue TRIM commands on a regular basis (calling it retrim).
You can force this by clicking the button labeled Optimize.
For devices with NAND flash memory, clicking this button reissues the TRIM command.
The base volumes recognize the TRIM command."
To elaborate, the command that causes the pages to be marked as invalid, or stale is the TRIM command. TRIM does
not inherently cause any pages to be marked as stale, though. When under heavy load, the SSD's controller may decide to still excecute the TRIM command but nevertheless refuse to perform the action that actually marks the pages as stale. I.e., to give priority to pending read/write operations in an attempt to keep up with performance.
That in fact is why Windows periodically does a retrim. There exists no such thing as a retrim command, though. Windows just sends the necessary TRIM commands again to try to ensure that any pages no longer in use by data objects that exist within the filesystem will (hopefully) be marked as stale.
The retrim usually will succeed due to the fact that the \Microsoft\Windows\Defrag\ScheduledDefrag task in Task Scheduler runs, weekly by default on Windows 11, as part of Windows Automatic Maintenance (WAM), which runs, daily at 3:00 AM for 1 hour by default on Windows 11, when the system is idle or until the system no longer is idle. If the ScheduledDefrag fails to complete in such a way that 30 days have elapsed since the last successful completion, the task will run as part of Emergency Maintenance.
Further, if "trimming process" here is referring to TRIM, then no, TRIM does
not cause any pages to be overwritten (or erased). Also, the garbage collection process does
not inherently cause any pages to be erased (or blocks, as pagess are grouped into blocks, and NAND cells can only be erased at the block level even though TRIM does mark individual pages).
In essence, whether a block is erased during garbage collection is determined by the manufacturer's SSD hardware design implementation, the SSD's firmware, and the background processes that the SSD's controller runs internally so they are kept trade secret at least in part. This not only includes the garbage collection process itself.
It also includes other processes like wear-leveling, corrective measures using Error Correction Codes (ECC) and various other data management techniques some of which may only be found in some SSDs. E.g., data refresh cycles.
https://www.innodisk.com/upload/file/innodisk_iretention_20_white_paper_en.pdf
The main takeway here is that it is impossible to know when the erasure occurs. So much so, in a lot of cases mostly involving only light use, a very large number of blocks will simply
never be erased. Worse, data gets moved around constantly in the NAND to reduce write amplification and to make processes like wear-leveling possible, and gets moved around such a way that each move usually leaves behind stale pages—not seldom in massive quantities.
Finally, this still holds true in spite of the fact that every modern PC normally has TRIM enabled by default. It also helps to explain why Sysinternals SDelete doesn't work on SSDs.