“Weak reference”: down to earth explanation needed

后端 未结 4 389
暗喜
暗喜 2021-02-04 03:17

Can someone provide an explanation of a weak reference in Delphi?

I noticed that the concept is often mentioned in some library/framework source code I scrutini

4条回答
  •  猫巷女王i
    2021-02-04 03:50

    In a most general case a strong reference controls the lifetime of a referenced instance while a weak reference does not. The term weak reference can be used in context of a garbage collector, reference counted interfaces or common objects.

    For example, a Delphi form hold the references to all its controls; these references can be called strong because when a form is destroyed its controls are also destroyed. On the other hand, a Delphi form's control has a reference to a form it belongs to. This reference can be call weak because it does not controls a form's lifetime in any way.

提交回复
热议问题