Garbage collection

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

    Garbage collection

    Hi,

    Lets take in mind the following scenario: Object A creates Object B and Object C, Object B and C are being initialized by object A so they reference each other ( Object B has a reference to object C and object C has a reference to object B ), no Object other then object A may use objects A and B so when object A is collected Objects A and B are not needed and should be collected as-well, Will objects A and B be collected by the GC?????
    Using COM I would use a weak reference so Objects A and B will not effect each others reference count this will assure that deletion of object A causes objects B and C to be deleted as-well, what would happen in managed code? Is there an equivalent to a weak reference ( of course this should be managed solely by the framework ), how does the framework treat is kind of scenario?

    Nadav

  • Simon Smith

    #2
    Re: Garbage collection

    On 19 Jul 2004 09:18, "Nadav" wrote:[color=blue]
    >Hi,
    >
    >Lets take in mind the following scenario: Object A creates Object B and Object
    >C, Object B and C are being initialized by object A so they reference each
    >other ( Object B has a reference to object C and object C has a reference
    >to object B ), no Object other then object A may use objects A and B so when
    >object A is collected Objects A and B are not needed and should be collected
    >as-well, Will objects A and B be collected by the GC?????
    >Using COM I would use a weak reference so Objects A and B will not effect
    >each others reference count this will assure that deletion of object A causes
    >objects B and C to be deleted as-well, what would happen in managed code?
    >Is there an equivalent to a weak reference ( of course this should be managed
    >solely by the framework ), how does the framework treat is kind of scenario?
    >
    >
    >Nadav
    >http://www.ddevel.com
    >[/color]

    This is the 'circular reference' problem and yes, .NET Garbage Collector
    handles it perfectly - because, in part, it *doesn't* use reference counting.
    When GC runs, it knows which objects are active (i.e. reachable) and thus
    which ones aren't. It then starts cleaning up all which aren't. There are
    loads of explanations of this on the web and in MSDN[1]. Read some of them
    - it's stuff you really should know if you're going to do anything in .NET.


    [1] Keywords: "Garbage Collection", GC, finalize, dispose, IDisposable,
    Generations, "finalizati on queue".
    --
    Simon Smith
    simon dot s at ghytred dot com
    www.ghytred.com/NewsLook - NNTP Client for Outlook


    Comment

    Working...