There are basically two reasons for just increasing address space: memory leakage and memory fragmentation.
In the leak, there is not much to do besides running tools such as cppcheck
and valgrind
so that they identify leaks.
The
cppcheck
will do the static analysis of the source code, and will identify errors as bad programming practices, allocated variables that go out of scope without being deallocated, etc. However, it is not very accurate since it performs only static analysis, but has the advantage of being faster.
While valgrind
will scan all memory allocations, performing deep application profiling, and will point all leaked memory in the application.
If they identify an error, they will give you information that will help you solve the problem (although not always clear).
In the case of memory fragmentation, what happens is that the memory is not allocated in small pieces (either by OS or runtime being used), but in memory pages (usually at least 4KB) , and then divide into smaller pieces.
However, if there is a page with only 4 bytes occupied, and if you want to occupy another 4KB, you can not take advantage of the page that is practically free, but rather allocate a new page. Note that it has formed a "hole" in one of the pages that was not used, but in this case it is large enough to be used again in an allocation throughout the program.
In some cases, however, the "hole" is too small and ends up being impossible to allocate it for some useful use. Of course this depends on how the program was developed, whether it usually deallocates large chunks of memory, or whether memory is allocated indefinitely, among other factors. But the important thing is that this can cause the program to allocate more and more memory, even though it is not exactly leaking, but only fragmenting.
One way to avoid these problems is to allocate as many variables as possible on the stack. So when they are out of scope, they are automatically released, avoiding memory leak. In addition, the heap is a region with always contiguous addresses and allocated in sequence, so memory fragmentation does not occur, in addition to having faster heap access.
Some components only deallocate memory when the entire component is deallocated. That is, imagine that you created the player and are playing videos on it. However, it has not been so well written, and it ends up saving a few (or several) bytes between one video and another rather than releasing them. However, programmers have taken care to free up memory when the component is destroyed. One option would be at the end of each video recreating the component (or every 2 videos, depends on your needs). Incredibly, I've seen this happen.
Anyway, the ideal solution is to find the leak and fix it. What's more, if in all these components the leak occurs, analyze if it is not occurring in your code rather than the code of the others. It may be that the error is very subtle, but with tools like valgrind
the error can be identified.
I hope I have helped with something, and sorry for the long text.