* jleslie48 <
[email protected]>:
If I simply set
an external pointer to e the fact that an active pointer is still
looking at the instance will prevent the garbage collector from
freeing that memory. any further call to the event handler will
create a new "e" instance, and the old one that I have pointed to by
my external pointer mp_e still has the old instance. ( I know, the
word pointer is a dirty word in the C# world but hey lets call a spade
a spade.)
Better call it reference. Although it is the same when it comes to
implementation in machine code, it is NOT the same in program code. A
pointer is explicitly used as such while a reference is dereferenced
automatically when needed, hidden from the programmer. Because both
concepts exist in C# (and, btw, also in C++), it makes sense to
distinguish them.
I assume that once I take mp_e and assign it a new value the old e
instance that it was pointing to is taken care of by the garbage
collector in the background correct?
It will eventually. A conservative garbage collector will look for
abandoned objects as soon as new memory is to be allocated. I don't know
the implementation details of the .NET garbage collector. The price you
pay for garbage collection is never knowing exactly when your object
will be destroyed. Most of the time, it doesn't matter.
Regards,
Felix
--
Felix Palmen (Zirias) + [PGP] Felix Palmen <
[email protected]>
web:
http://palmen-it.de/ |
http://palmen-it.de/pub.txt
my open source projects: | Fingerprint: ED9B 62D0 BE3932F9 2488
http://palmen-it.de/?pg=pro + 5D0C 8177 9D80 5ECF F683