1. <legend id='bEUBa'><style id='bEUBa'><dir id='bEUBa'><q id='bEUBa'></q></dir></style></legend>
      <tfoot id='bEUBa'></tfoot>
      • <bdo id='bEUBa'></bdo><ul id='bEUBa'></ul>

        <small id='bEUBa'></small><noframes id='bEUBa'>

        <i id='bEUBa'><tr id='bEUBa'><dt id='bEUBa'><q id='bEUBa'><span id='bEUBa'><b id='bEUBa'><form id='bEUBa'><ins id='bEUBa'></ins><ul id='bEUBa'></ul><sub id='bEUBa'></sub></form><legend id='bEUBa'></legend><bdo id='bEUBa'><pre id='bEUBa'><center id='bEUBa'></center></pre></bdo></b><th id='bEUBa'></th></span></q></dt></tr></i><div id='bEUBa'><tfoot id='bEUBa'></tfoot><dl id='bEUBa'><fieldset id='bEUBa'></fieldset></dl></div>

        任务和垃圾收集存在哪些问题?

        时间:2023-09-13

              <tbody id='47Ukb'></tbody>

                <bdo id='47Ukb'></bdo><ul id='47Ukb'></ul>
                1. <small id='47Ukb'></small><noframes id='47Ukb'>

                2. <legend id='47Ukb'><style id='47Ukb'><dir id='47Ukb'><q id='47Ukb'></q></dir></style></legend>

                  <tfoot id='47Ukb'></tfoot>

                  <i id='47Ukb'><tr id='47Ukb'><dt id='47Ukb'><q id='47Ukb'><span id='47Ukb'><b id='47Ukb'><form id='47Ukb'><ins id='47Ukb'></ins><ul id='47Ukb'></ul><sub id='47Ukb'></sub></form><legend id='47Ukb'></legend><bdo id='47Ukb'><pre id='47Ukb'><center id='47Ukb'></center></pre></bdo></b><th id='47Ukb'></th></span></q></dt></tr></i><div id='47Ukb'><tfoot id='47Ukb'></tfoot><dl id='47Ukb'><fieldset id='47Ukb'></fieldset></dl></div>
                3. 本文介绍了任务和垃圾收集存在哪些问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在使用派生自任务并行库的 API 和类时,开发人员何时需要关注垃圾回收的影响?

                  When does a developer need to be concerned with the effects of garbage collection when using APIs and classes derived from the Task Parallel Library?

                  .NET 任务实例能否超出范围在运行期间?,似乎会给您一种安全感,您不必担心将任务保持在范围内.但是,问题似乎仅限于在 ThreadPool 上运行的任务,然后它们由 ThreadPool root.但是,如果我理解 这篇 MSDN 博文正确地,来自该 SO 问题的建议并不普遍适用,因为来自 TaskCompletionSource 的任务并非类似 rooted.

                  Can .NET Task instances go out of scope during run?, would seem to give a sense of security that you do not have to worry about keeping tasks in scope. However the question seems limited to Tasks running on the ThreadPool where they are then rooted by the ThreadPool. However, if I understand this MSDN blog post correctly, the advice from that SO question is not be generally applicable because Tasks from TaskCompletionSource are not similarly rooted.

                  直接使用 TaskCompletionSource 是唯一需要关注的时间吗?
                  但是,在使用 API 时,您不知道 Task 来自何处.如果提供的 Task 来自 TaskCompletionSource 或其他一些非根源,您是否需要担心存储对延续的引用?

                  Are direct use of TaskCompletionSource the only time of concern?
                  However, when consuming an API you do not know where the Task came from. Do you then need to worry about storing references to continuations in case the provided Task came from a TaskCompletionSource or some other non-rooted source?

                  这似乎很快变得不方便和复杂,因为需要考虑任务是否已植根(异步 I/O 任务是否植根?).我正在努力寻找有关该主题的大量信息,但它是一个足够流行的库遗漏或误解某事.

                  This seems to get inconvenient and complex quickly from needing to consider whether the Task is rooted or not (are Async I/O Tasks rooted?). I am struggling to find much for information on topic but it a popular enough library I feel I should not need to be reading decompiled source code to determine if I need to worry about race-conditions with the garbage collector, so I figure I must be missing or misunderstanding something.

                  推荐答案

                  当你有未完成的TaskCompletionSource,那么总有两种选择:

                  When you have uncompleted TaskCompletionSource, then there are always two options:

                  1. 将来可能会完成该 TCS.这意味着某个东西持有对 TCS 的引用,这意味着它不能被 GCed.

                  1. Something might complete that TCS in the future. That means that that something holds a reference to the TCS, which means it can't get GCed.

                  正常规则仍然适用于该内容,因此您可能需要担心保持其扎根.

                  Normal rules still apply to that something, so you might need to worry about keeping that rooted.

                  没有什么可以完成该 TCS.这意味着 TCS 及其任务可能很快就会被 GCed,但没有工作未完成的风险(因为没有工作).

                  Nothing will ever complete that TCS. That means the TCS and its Task will likely get GCed soon, but there is no risk of work not being done (because there is no work).

                  这篇关于任务和垃圾收集存在哪些问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:我是否需要在对象被孤立之前从对象中删除事件订阅? 下一篇:静态成员的垃圾收集

                  相关文章

                  <small id='am9ks'></small><noframes id='am9ks'>

                  <legend id='am9ks'><style id='am9ks'><dir id='am9ks'><q id='am9ks'></q></dir></style></legend>
                    <bdo id='am9ks'></bdo><ul id='am9ks'></ul>

                  1. <i id='am9ks'><tr id='am9ks'><dt id='am9ks'><q id='am9ks'><span id='am9ks'><b id='am9ks'><form id='am9ks'><ins id='am9ks'></ins><ul id='am9ks'></ul><sub id='am9ks'></sub></form><legend id='am9ks'></legend><bdo id='am9ks'><pre id='am9ks'><center id='am9ks'></center></pre></bdo></b><th id='am9ks'></th></span></q></dt></tr></i><div id='am9ks'><tfoot id='am9ks'></tfoot><dl id='am9ks'><fieldset id='am9ks'></fieldset></dl></div>

                    1. <tfoot id='am9ks'></tfoot>