How to handle lifecycle of dynamically allocated data in Windows messages?

Posted by nang on Stack Overflow See other posts from Stack Overflow or by nang
Published on 2010-06-16T10:07:37Z Indexed on 2010/06/16 10:12 UTC
Read the original article Hit count: 228

Filed under:

Simple task: Send a windows message with dynamically allocated data, e.g. an arbitrary length string. How would you manage the responsibility to free this data?

The receiver(s) of the windows message could be responsible to free this data. But: How can you guarantee that all messages will actually be received and thus the linked data will be freed? Imagine the situation that the receiver is shutting down, so it won't process it's message queue any more. However, the message queue still exists (for some time) and can still accept messages, which won't be processed any more.

Thanks!

© Stack Overflow or respective owner

Related posts about windows-messages