event subscription question

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

    #1

    event subscription question

    lets say i have an object with a bunch of events called ObjectA.

    i subscribe to ObjectsA events with ObjectB methods

    I set ObjectA to null.



    what happens to my subscriptions?

    Will ObjectA get garbaged collected?

    If I set ObjectA to another object of the same type, will the subscriptions
    switch?

    Thanks in advanced!

    Dan


  • Jon Skeet [C# MVP]

    #2
    Re: event subscription question

    Dan H. <DapperDanH@NO. comcast.SsPpAaM m.net> wrote:[color=blue]
    > lets say i have an object with a bunch of events called ObjectA.
    >
    > i subscribe to ObjectsA events with ObjectB methods
    >
    > I set ObjectA to null.
    >
    > what happens to my subscriptions?[/color]

    Nothing - if the object is garbage collected, then the delegates will
    become eligible for garbage collection too.
    [color=blue]
    > Will ObjectA get garbaged collected?[/color]

    Only if there aren't any other references to the object.
    [color=blue]
    > If I set ObjectA to another object of the same type, will the subscriptions
    > switch?[/color]

    No.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...