开发者

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

开发者 https://www.devze.com 2023-01-20 15:54 出处:网络
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

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

精彩评论

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