gpt4 book ai didi

c# - ASP.NET 垃圾回收 : is referencing static class property dangerous?

转载 作者:太空宇宙 更新时间:2023-11-03 21:12:15 25 4
gpt4 key购买 nike

假设“MyModel”类包含以下属性:

public List ListOfAlbumsTitles => AlbumsHelper.ListOfAlbumsTitles;

AlbumsHelper 是一个静态类。这是否意味着 MyModel 的对象不会因为引用静态类属性而被自动收集?

最佳答案

不,MyModel 的实例将被很好地处理。 MyModel 存储的是对恰好在别处(即在 AlbumsHelper 中)正在使用的东西的引用。

在垃圾收集方面,引用是单向的。因此,从 FooBar 的引用将使 Foo 保持事件状态,只要 Bar 存在。反之则毫无意义。

关于c# - ASP.NET 垃圾回收 : is referencing static class property dangerous?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36902177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com