C#: Create strong reference between objects, without one referencing the other

后端 未结 4 1234
时光取名叫无心
时光取名叫无心 2021-02-13 23:55

Suppose I have 2 classes, Foo and Bar. Foo does not have (and cannot have) a relation to Bar.

However, I want a bar instance to stay alive, as long as it\'s foo instance

4条回答
  •  半阙折子戏
    2021-02-14 00:18

    Bar can only not be finalized if SOMETHING has a reference to it. Just have Foo tell that thing when it can let go of Bar.

提交回复
热议问题