MFCaptureToFile (Windows7SDK sample) memory leak RRS feed

  • Question

  • Please teach me how to not cause a memory leak.

    Development environment is Windows10 and VisualStudioProfessional2015 Update3.


    I confirmed the above, but I think that there is a problem with WriteSample() instead of ReadSample().  Because memory leak does not occur by commenting WriteSample().

    Thursday, October 19, 2017 5:05 AM

All replies

  • Why do you think there is a memory leak?

    Sam Hobbs

    Thursday, October 19, 2017 6:45 PM
  • Thank you for your reply.
    I started debugging without changing anything on MFCaptureToFile.
    I monitored the diagnostic tool of VS 2015 and the value of Widows performance monitor ("Private Bytes" and "Working Set - Private").
    According to this, it seems that it leaks about 1 MB in 10 minutes.
    If you have the same environment, would you please try it?
    Friday, October 20, 2017 12:51 AM
  • Can you use a debug build and execute it with the debugger? If there are memory leaks then the debugger will tell you that there are. If the debugger does not say there are memory leaks then you probably don't.

    Sam Hobbs

    Friday, October 20, 2017 2:14 AM
  • I confirmed with the debugger, but the memory increase / decrease is not constant. This is because WriteSample is asynchronous processing.
    You can understand it graphically with Performance Monitor.
    Maybe the memory increase is the MediaFoundation specification?
    Friday, October 20, 2017 2:58 AM
  • Window's use of memory is complicated. People tend to think it is simple and understandable but it is not simple. Windows uses memory in many ways, many more than you realize (I assume).

    Windows does not clean up memory as soon as it is freed. Some memory can be considered allocated just because Windows does not free up memory unless it needs to. Long before the garbage collector in .Net, Windows had the feature to keep memory that has been freed in the lists as if it is allocated.

    I certainly do not know the details. I do know that the performance analyzer is useless for determining if there is a memory leak. You cannot and should not assume that there is a memory leak just because memory increases.

    You are not being specific about anything that is useful for determining if there is a memory leak. My assumption is that there is not a memory leak; you just think there is.

    Sam Hobbs

    • Unproposed as answer by JAM-S Wednesday, November 15, 2017 9:03 AM
    Friday, October 20, 2017 4:45 AM
  • Thanks for the advice.
    When creating a project using SinkWriter, I think that everything will be in doubt.
    Because there was no information in this part, I contributed it here.
    I would like to wait a little more useful information. Thank you.

    I am most glad that there is an answer from Microsoft ...
    Friday, October 20, 2017 5:26 AM