Message.Dispose()

Method

Declaration

void Dispose()

Purpose

Release native storage associated with the message.

Remarks

Messages occupy storage outside of the .NET environment (that is, in the native C environment) and also within the .NET environment. When the .NET garbage collector recycles the .NET message object, this action triggers release of the corresponding native storage as well.

However, the timing of garbage collection is unpredictable, delaying the release of native storage as well. In applications where efficient management of native storage is a critical performance factor, you can use this method to explicitly free the native storage.

Call this Dispose method at the end of a message callback method to immediately free the native storage associated with the message. The .NET message object is independent of the native storage (and independent of this method), and it remains intact until the .NET garbage collector recycles it in the usual way.

Attempting to access the message after calling this method results in an exception.