GC.ReRegisterForFinalize

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shree

    GC.ReRegisterForFinalize

    Hi All,
    I wanted to know the use case when one needs to call
    gc.reregisterfo rfinalize. Can anyone help? I only know that call this
    function it adds its argument back to the finalization queue. When
    would/should one need to do this?

    Thanks.
  • Alberto Poblacion

    #2
    Re: GC.ReRegisterFo rFinalize

    "Shree" <Shree.S.Joshi@ gmail.comwrote in message
    news:83339ef3-80ea-4b43-a4d5-99968868a2d0@34 g2000hsh.google groups.com...
    I wanted to know the use case when one needs to call
    gc.reregisterfo rfinalize. Can anyone help? I only know that call this
    function it adds its argument back to the finalization queue. When
    would/should one need to do this?
    Ideally, you should never have to use this function. It is only needed if
    you resurrect an object from within its Finalizer (which is not a good
    idea), and you want your resurrected object to Finalize again once it
    becomes again unreachable and it is garbage-collected for a second time.
    Essentially, ReRegisterForFi nalize adds your object (again) to the
    Finalization queue, from where it had already been removed since the
    Finalizer was already running.
    You resurrect an object from the Finalizer if you make it Reachable (it
    was unreachable or the Finalizer would not be running) by assigning a
    reference to it ("this") into a reachable location such as a static
    variable.

    Comment

    • KWienhold

      #3
      Re: GC.ReRegisterFo rFinalize

      On 22 Aug., 12:18, "Alberto Poblacion" <earthling-
      quitaestoparaco ntes...@poblaci on.orgwrote:
      It is only needed if
      you resurrect an object from within its Finalizer (which is not a good
      idea),
      Couldn't you also call SupressFinalize (this) and later do something
      that once again would require the finalizer to run? (I realize that in
      most cases this would mean calling Dispose() and then doing something
      with the disposed object, which is a bad idea in any case)

      Kevin Wienhold

      Comment

      Working...