For SQL server a local temporary table - i.e. a table created with
CREATE TABLE #TempTableName ...
is automatically removed when the session or stored procedure ends.
So if you write it within a stored procedure, then it is cleared up and removed when the procedure exits.
Otherwise, it is destroyed when that session ends - which means when the SqlConnection is closed.
For a global temporary table - i.e. a table created with
CREATE TABLE ##TempTableName ...
it is slightly different.
In this case, it is destroyed when the session that created it and the last session referencing it ends. This is to allow multiple users access to the same temporary data.