C++ code:
person* NewPerson(void)
{
person p;
/* ... */
return &p; //return pointer to person.
}
C# code:
person
The scoping rules in this example are analogous but in C# if the returned value is assigned to something then it will not be garbage collected as long as something holds a reference to it. If it's not assigned to something, nothing holds a reference to it and it will be garbage collected next time the collector executes