c# - Is object eligible for garbage collection if it's created within using-statement and not explicitly bound to a reference? -
i have (illustration only) c# code:
using( new system.io.memorystream() ) { system.threading.thread.sleep(1000); }
note here memorystream
created , not explicitly bound reference. unless there's special treatment because of using
statement object has no references , collected before control leaves using
statement , maybe before sleep()
completes.
is memorystream
eligible collection before control leaves using
statement?
no, not.
behind scenes, hidden reference memorystream
has been created, still alive.