eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.22k stars 169 forks source link

Memory Leak #220

Open dcRolls opened 3 years ago

dcRolls commented 3 years ago

This is a great tool. I've found, however, that the code appears to leak memory. I understand that it consumes memory to track the function calls, but when I limit scope by putting braces around a block of code which uses mocking, I still end up with an increase in memory, the size of which depends on the number of methods you are mocking. This is true even if I never actually call those methods.

`//Record initial memory footprint here:

     { //limit scope
        std::vector<IMySolid*> myObjs;
        Mock<IMySolid> mock;
        Method(mock, getShapeCount) = 1;
        Method(mock, getShapeCategory) = 1;
        myObjs.push_back(&mock.get());

        for (std::vector<IMySolid*>::const_iterator it = myObjs.begin(); it != myObjs.end(); it++)
        {
           ;//don't actually call either mocked method             
        }
     } //end of scope 

//record new memory footprint here... this leads to an increase in memory of 119 bytes, when the same code executed with the real solid results in no memory increase.`

Am I doing something wrong, or is there a memory leak?

Thanks.

FranckRJ commented 1 year ago

Looks like the mocks are never deleted for instance (at least I didn't find where they were by looking at the source code).

So there's at least that, but there can be more, I need to investigate further.