Re: Accessing private data during finalize/dispose
From: TB (tbrown92030_at_kaxy.NOSPAM.com)
Date: 02/05/04
- Next message: Dan: "Re: Looping through datagrid rows"
- Previous message: Craig Kenisston: "Re: NNTP class ?"
- In reply to: Stoitcho Goutsev \(100\) [C# MVP]: "Re: Accessing private data during finalize/dispose"
- Next in thread: Stoitcho Goutsev \(100\) [C# MVP]: "Re: Accessing private data during finalize/dispose"
- Reply: Stoitcho Goutsev \(100\) [C# MVP]: "Re: Accessing private data during finalize/dispose"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 5 Feb 2004 14:41:05 -0800
----- Stoitcho Goutsev (100) [C# MVP] wrote: -----
Hi TB,
> Are some types accessible (int, char, double) but others not (string)?
All data members of value types (int, char, double, enums, structs ) are
accessible, but reference types (strings, arrays, declared as classes) are
not guaranteed.
Ok, this is what I gathered from reading the documentation. But this seems to contradict what you say next...
> Can I still refer to 'm_Manager' here? I know I can do so reliably in the
"if (disposing)" conditional -- but I need to unmark the object even if the
calling code forgets to call Dispose on my object! I could duplicate the
code necessary to unmark the object but need to keep two strings and an int
to be able to do it. I'm reasonably sure that 'int' private data is
accessible during finalization, but how about strings?
Since class A doesn't declare *finalizer* that means you won't use any
unmanaged resources from A then "Yes, you can access m_Manager safely".
Why? Because class-B objects have finalizers. When they become garbage they
will be moved to the freachable queue, which is considered as a *root*
all objects referenced from class-B objects are still alive. Finalizers will
be executed by a worker thread and after that class-B objects will be
eligable for GC. How you can see class-A will be collected not before
finalization of the last class-B object it has created.
Let me see if I have this right...
Because my class B declares a finalizer (the ~B( ) "destructor"), it will be placed on the finalizer queue when garbage collected and kept "live". Because it is still "live" in this queue, any reference the class B instance holds is still valid -- even if these are to reference types (strings, arrays, classes). [doesn't this contradict the statement above??]
However, if class A also declared a finalizer (a ~A( ) "destructor"), then I would be SOL because both A and B instances would be placed in the finalizer queue and, although both are "live" while in the queue, their order of finalization is indeterminate and I can't guarantee that the reference to the A object inside of B is still valid when B's finalizer is eventually called.
So..., in this type of pattern, where a subordinate class object maintains a reference to a supervising object and needs access to it during finalization it is critical that the supervising class *not* implement a finalizer!!
Have I got it right??
Thanks!
-- TB
- Next message: Dan: "Re: Looping through datagrid rows"
- Previous message: Craig Kenisston: "Re: NNTP class ?"
- In reply to: Stoitcho Goutsev \(100\) [C# MVP]: "Re: Accessing private data during finalize/dispose"
- Next in thread: Stoitcho Goutsev \(100\) [C# MVP]: "Re: Accessing private data during finalize/dispose"
- Reply: Stoitcho Goutsev \(100\) [C# MVP]: "Re: Accessing private data during finalize/dispose"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|