Is Delegate.EndInvoke() really necessary?

前端 未结 7 1925
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 08:28

I\'ve read a couple of forums and even a stackoverflow question or two saying that Delegate.EndInvoke is necessary when using Delegate.BeginInvoke. Many of the articles I\'

相关标签:
7条回答
  • 2020-11-29 09:06

    I heard sth about memory leak issues that may arises.

    By a keyword search, I found a good discussion.

    Does not calling EndInvoke *really* cause a memory leak ?

    It can but it won't necessarily. Technically there is no such thing as a memory leak in .NET. Eventually the memory will be reclaimed by the GC. The problem is that it might be around a long time. The reason that you should call EndInvoke is because the results of the invocation (even if there is no return value) must be cached by .NET until EndInvoke is called. For example if the invoked code throws an exception then the exception is cached in the invocation data. Until you call EndInvoke it remains in memory. After you call EndInvoke the memory can be released.

    Here is the reference,

    Another Reference

    0 讨论(0)
提交回复
热议问题