I am testing our code for memory leaks, and I've found that the memory used continually increases with time which is unacceptable. I am assuming this is an issue with our code. Anyway, I created a bare bones test, which repeatedly loads and unloads the engine. Then I used the Visual Studio Performance and Diagnostics tools to analyses memory after each loop. I find that memory usage increases with time.

Here is the test code (with the licence key removed) which repeatedly loads and unloads the ABBYY engine:

void Test_3() { while (true) { std::cout << "Press x then Enter to exit, or Enter to continue ..."; int cval = getc(stdin); if (cval == 'x') { break; }

    CLSID clsid = __uuidof(FREngine::InprocLoader);
    UUID iid = __uuidof(FREngine::IEngineLoader);
    FREngine::IEngineLoaderPtr engineLoaderPtr;
    HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, (void**)&engineLoaderPtr);
    if (hr != S_OK)
        if (hr == REGDB_E_CLASSNOTREG)
            std::cout << "REGDB_E_CLASSNOTREG" << std::endl;
            std::cout << "Error: unable to create the engine" << std::endl;

        FREngine::IEnginePtr engine = engineLoaderPtr->GetEngineObject(L"[the licence key]");

        engine = nullptr;
        engineLoaderPtr = nullptr;

    catch (_com_error&)
        std::cout << "Error: unable to load the ABBYY FineReader COM object" << std::endl;
    catch (...)
        // No special processing needed
        std::cout << "Error: unknown reason" << std::endl;


I get much bigger increases in memory usage with more complex scenarios - loading images and extracting test - but the above is nice and easy to describre.

asked 22 Nov '16, 17:35

Leif's gravatar image


Please try to swap 2 rows in your code so that the engine gets destructed before deinitialization. You can apply this code sample:

engine = nullptr; engineLoaderPtr->ExplicitlyUnload(); engineLoaderPtr = nullptr;

Please let us know about the results.

(23 Nov '16, 18:59) Anna Fedyush... ♦♦

Thank you Anna.

To test your suggestion I repeatedly loaded and unloaded the engine, and recorded memory use every 50 iterations. The results are as follows:

Iteration   Memory change    Memory
0           0                124KB
50          +457KB           581KB
100         +24KB            606KB
140         -77KB            528KB
200         +72KB            600KB
250         +2.7MB           3.29MB
300         +1.69MB          4.97MB
350         -443KB           4.54MB
400         -2.37MB          2.17MB
450         +11KB            2.18MB

So the net result is a large increase in memory usage. This is for us not an issue since we only load and unload once per session. But I also see large memory increases when we load and process images. I'll write a simple example unit test.


answered 24 Nov '16, 16:40

Leif's gravatar image


edited 24 Nov '16, 16:41

Thank you again for your help. I've located the cause of the large memory increases that we see when loading an image into a document, and closing the document, and the issue is in our code. Basically I made an error when marshalling interfaces between threads, which meant COM interfaces were not being released. I have further testing to do, but in the meantime apologies for troubling you.


answered 24 Nov '16, 19:27

Leif's gravatar image


Happy to know that you have solved the issue! :)

(25 Nov '16, 11:34) Anna Fedyush... ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 22 Nov '16, 17:35

Seen: 291 times

Last updated: 25 Nov '16, 11:34

© 2016 ABBYY. All rights Reserved. www.ABBYY.com | Privacy Policy | Legal