cineform-sdk icon indicating copy to clipboard operation
cineform-sdk copied to clipboard

Memory leak caused by CFHD_PrepareToEncode (Windows only?)

Open bluetarpmedia opened this issue 2 years ago • 0 comments

There appears to be a memory leak when calling CFHD_PrepareToEncode. I've only tested on Windows 10.

I first observed this in some unit tests for my encoder (the unit test calls _CrtDumpMemoryLeaks), so to try and confirm the problem, I tried an infinite loop of creating an encoder, calling PrepareToEncode, and closing the encoder, to see how the process VM usage grows over time.

Using 8fd6bba from 'master' (9 Nov 21), build the solution with VS 2019 x64, and then insert the following at the very start of main() in TestCFHD.cpp

while (true)
{
    CFHD_EncoderRef enc = nullptr;
    CFHD_Error res = CFHD_OpenEncoder(&enc, nullptr);
    if (res != CFHD_ERROR_OKAY)
        return res;

    res = CFHD_PrepareToEncode(
        enc,
        320,
        160,
        CFHD_PIXEL_FORMAT_RG24,
        CFHD_ENCODED_FORMAT_YUV_422,
        CFHD_ENCODING_FLAGS_NONE,
        CFHD_ENCODING_QUALITY_DEFAULT);
    if (res != CFHD_ERROR_OKAY)
        return res;

    CFHD_CloseEncoder(enc);
}

Watch the process memory usage in something like Windows Task Manager.

The VM usage grows sharply with smaller resolutions (like 160x80, 320x160, etc) but much slower with higher resolutions.

image

bluetarpmedia avatar Nov 09 '21 04:11 bluetarpmedia