FreeMediaType function

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The FreeMediaType function deletes the format block in an AM_MEDIA_TYPE structure.


void FreeMediaType(


mt [ref]

A reference to an AM_MEDIA_TYPE structure.

Return value

This function does not return a value.


The format block is allocated on the heap. The pbFormat member of the AM_MEDIA_TYPE points to the format block. Use this function to free just the format block. To delete an allocated AM_MEDIA_TYPE structure, call DeleteMediaType.

This function is defined in the DirectShow Base Classes library. If you prefer not to link to the base class library, you can use the following code:

// Release the format block for a media type.

void _FreeMediaType(AM_MEDIA_TYPE& mt)
    if (mt.cbFormat != 0)
        mt.cbFormat = 0;
        mt.pbFormat = NULL;
    if (mt.pUnk != NULL)
        // pUnk should not be used.
        mt.pUnk = NULL;


Requirement Value
Mtype.h (include Streams.h)
Strmbase.lib (retail builds);
Strmbasd.lib (debug builds)

See also


Media Type Functions