garbage collection - from C++ to C#: Never Return a Reference to a Local Object? -
there's advice in c++: "never return reference local object", below quoted "c++ primer":
"there's 1 crucially important thing understand returning reference: never return reference local variable.
"when function completes, storage in local objects allocated freed. reference local object refers undefined memory after function terminates. consider following function:
// disaster: function returns reference local object const string &manip(const string& s) { string ret = s; // transform ret in way return ret; // wrong: returning reference local object! } "this function fail @ run time because returns reference local object. when function ends, storage in ret resides freed. return value refers memory no longer available program."
question: still apply c#? or doesn't matter gc introduced?
it not possible return references local variables in .net
Comments
Post a Comment