The WinSCP .NET assembly Session
class has the Dispose
method. Though it's probably hidden by C++/CLI. You call the Dispose
indirectly using the delete
. See How do you dispose of an IDisposable in Managed C++ and Calling C++/CLI delete on C# object.
Generally, even if you do not, the garbage collector will do this for you (in an unpredictable moment), as you do not keep reference to old sessions. But it definitely won't let your machine run out of memory.
On the other hand, you NEED to call the Dispose
(the delete
) to close the unused sessions anyway, otherwise you may run out of allowed connections to the servers (or even exhaust servers' resources).
If you want to check, if and when the session is disposed, set the Session.DebugLogPath
and search a log for an entry like:
[2014-04-23 08:08:50.756Z] [000a] Session.Dispose entering
Your question whether there's a chance for a memory leak, when a program finishes is irrelevant. Any memory allocated by a process is released by an operating system when the process finishes. No matter what leak/bug/anything is in the program itself. See also Does the heap get freed when the program exits? Anyway, I believe your code does not leak memory.