eranpeer / FakeIt

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

AlwaysDo - high memory usage #76

Closed jansvoboda11 closed 7 years ago

jansvoboda11 commented 7 years ago

Hello. I've noticed a lot of memory being allocated when using AlwaysDo in my tests. Memory usage steadily increases when a mock is used in long-running loop. You should be able to reproduce it by running the code below.

#include <standalone/fakeit.hpp>

using namespace fakeit;

struct Foo { virtual void bar() = 0; };

int main() {
  Mock<Foo> fooMock;
  When(Method(fooMock, bar)).AlwaysDo([] {  });
  Foo &foo = fooMock.get();

  while (true) { foo.bar(); }

  return 0;
}

Is this a bug in the library, or am I doing something wrong? Thanks for your answer.

eranpeer commented 7 years ago

Sure, the mock records every call. Hence the memory is expected to increase in such a loop.

On Dec 28, 2016 1:33 PM, "Jan Svoboda" notifications@github.com wrote:

Closed #76 https://github.com/eranpeer/FakeIt/issues/76.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/eranpeer/FakeIt/issues/76#event-906449452, or mute the thread https://github.com/notifications/unsubscribe-auth/ACc8gky4YpieEZ8pNTKwuk0jf8KzzgcGks5rMkj2gaJpZM4LWpAA .

jansvoboda11 commented 7 years ago

Yeah, I've realised that the next day, thanks for the reply.