Forcing the operating system to clean up after the "routine",

I am writing an image processing program in C ++. For this purpose, I changed a third-party program (edge ​​detector) into a static library that I use in my program.

It smoothes the original edge detector, based on the OS, to clear the memory after performing the main function. Unfortunately, after I changed this original code, the main function became a “regular”, repeatedly called function, and therefore automatic cleaning is not performed. The result is a huge memory leak every time the function is called.

I cannot fully scan the entire detector code to fix this. Therefore, I would like to ask: in general, is there a way to separate the "subprogram" of the entire program (in my case, from the detector) from the rest and force the OS to clear after the subprogram, as if it were a stand-alone program? Could there be a solution using threads, for example?

Thank you for your responses.

+4
source share
2 answers

If you are using the * nix platform, perhaps you could fork library call.

0
source

You can run it in a separate process that will be removed from your program.

There are ways to pass the stdin child process, stdout, so you can control it.

What you can also try is to use valgrind to detect leaks and fix them.

If you are running Linux, you can use google for: fork () or system () to create a child process.

0
source

Source: https://habr.com/ru/post/1495733/


All Articles