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 small 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?
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.