I have a function in C# 2.0 called Foo(), that returns a value of the type boolean. I am instantiating an object in the function that I am not destroying before returning the boolean value. I want to know whether is it necessary to destroy the objects created before returning the value?
thanks.
No it isn’t. If you Foo method creates value types, they are located on the stack and thus cleaned-up as the stack is unwound. If you create reference types, your reference to these instances will go out of scope as the method exits and the instances will therefore be up for garbage collection.