Chris,
| I still think my answer applies. As long as there is a reference to the
| object, then GC will not collect it. _w is declared outside of the
| function so there is no way that the object that _w points to will be
| collected until something like _w = nothing happens.
No, Boni is asking about WeakReference.Target, not the WeakReference itself.
_w is the WeakReference object itself & is subject to normal GC rules (what
you have been stating)
_w.Target is the "weak reference", and is subject to special GC rules, if
the only reference to the object that _w.Target refers to is _w.Target
itself & the GC needs more memory, then it can release the object that
_w.Target refers to. In which case _w.IsAlive will be false & _w.Target will
return false.
In other words _w.IsAlive is short hand for (_w.Target IsNot Nothing)
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
| Boni wrote:
| > Oooh, I am sorry, my question is incorrect.
| > It should be:
| > How is it guaranted, that between (1) and(2) GC will not collect the
object
| > on which _w points.
| >
| >
| > | >
| >>Boni wrote:
| >>
| >>>Dear all,
| >>>------
| >>>Dim _w as weakreference
| >>>func XXX as mytype
| >>>(1)if _w.isalive orelase _w.target is nothing then return nothing
| >>>(2)return _w.target
| >>>end func
| >>>----
| >>>How is it guaranted, that between (1) and(2)
| >>>GC will not remove _w?
| >>>Thanks,
| >>>Boni
| >>>
| >>>
| >>>
| >>
| >>You have declared _w in a class here I assume, since it is not in a
| >>function. That being the cass _w will not be released until after the
| >>class goes out of scope. This means as long as the class is alive, _w
| >>will be. GC can do nothing to _w withing your function you show here
| >>
| >>Chris
| >
| >
| >
|
| I still think my answer applies. As long as there is a reference to the
| object, then GC will not collect it. _w is declared outside of the
| function so there is no way that the object that _w points to will be
| collected until something like _w = nothing happens.
|
| Chris