?? Ref parameters are not garbage collected ??

  • Thread starter Thread starter Filippo
  • Start date Start date
F

Filippo

I was told that if you pass a "ref param", the garbage collector does keep a
reference and therefore you need to dispose by yourself of the object
itself.

Is that true ?

Filippo
 
Filippo said:
I was told that if you pass a "ref param", the garbage collector does keep a
reference and therefore you need to dispose by yourself of the object
itself.
Is that true ?

The 'ref' keyword indicates to the compiler that - instead of a pointer to a
class - it should pass a pointer to a pointer to a class. That's all; it has
no impact on [the lack of] garbage collection. So no, even if you pass a
class by ref, it will still be automatically garbage collected if it isn't
reachable anymore from your code.

Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
 
Back
Top