开发者

Why will STA thread "leak small amounts of memory" if it fails to dispatch Windows messages?

After carefully reading this KB article I noticed an interesting statement there. The article says that if I have an STA thread and that thread doesn't dispatch Windows messages then that thread

  • will be unable to receive COM events form a COM server
  • can cause message broadcasters to hang (and thus sometimes cause a deadlock)
  • surprisingly... will leak smal开发者_如何学Gol amounts of memory

While the first two statements are rather reasonable - Windows messages are used for dispatching COM calls to objects in single-threaded apartments - I don't get the third one at all.

Why exactly will a thread "leak small amounts of memory" if it doesn't dispatch Windows messages?


I would imagine because that a struct is allocated, and posted with the message. If the message is not processed, the struct containing the message parameters will not be freed.


The messages that you're failing to dispatch - they must be queued up somewhere, waiting for that fateful moment at which you'll finally start dispatching them. That queue is going to use some memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜