120: Fix gltext memory leak (and other mem leaks) #166
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
120: Fix gltext memory leak (and other mem leaks)
Linked issues
Fixes #120
Fixes #118
Summarize your change.
Fixed the gltext memory leak by fixing the PyUnicode_AsUTF8String() which was used without its associated Py_XDECREF().
Note that this memory leak occurred not only in gltext but also whenever an Python RV package was calling an RV cmd with text parameters.
Describe the reason for the change.
This fix addresses the following Open RV reported issue:
#120
Problem:
Using gltext seems to cause a memory leak issue.
The reporter provided an example mode that creates a watermark using gltext that shows the issue, however it seems to also happen with the Color Inspecter tool shipped with Openrv (uses gltext). Memory usage of RV will continue to increase causing RV to slow down and or eventually crash.
Cause:
I was able to identify the source of the memory leak using XCode/instruments.
The leak is in the Python->Mu code (PyModule::py2mu()) which is reponsible of converting Python objects to Mu objects.
More specifically when converting a Python string to Mu.
PyUnicode_AsUTF8String() was used without its associated Py_XDECREF().
Solution:
Added Py_XDECREF().
Also in this commit:
A mechanics was put in place 4 years ago to prevent a playback during a review session from being interrupted by the garbage collector which was causing some playback hiccups ie skipped frames. We had decided to disable the garbage collector during the playback which resolved the Marvel’s issue. Now because of this mechanism, the Color Inspector tool (or any mu code being executed) will 'seem' to leak memory during playback but as soon as the playback is stopped then the garbage collector will do its job and makes all the ‘allocated memory’ during the playback, available again to the RV process. However, the side effect is that RV will have a bigger memory footprint : proportional to whatever memory is allocated in Mu scripts from the start of the playback until the playback is stopped.
As decided this morning at the RV dailies, I have added an environment variable to disable this mechanism if desired. The no garbage collector cleanup up during playback would be the default behaviour and would guarantee that no hiccups occur during playback.
To re-enable the garbage collector from operating during a playback:
export RV_DISABLE_GARBAGE_COLLECTION_DURING_PLAYBACK=0
Also in this commit:
Fixed a Typo in addSourcesVerbose where sring was used instead of string.
(Most probably my bad!)
Describe what you have tested and on which operating system.
This commit was successfully built on all 3 platforms and tested on macOS Monterey.
Testing Protocole:
Please validate repro steps.
I recommend using the following command which uses 60 fps to speed up the memory leakage:
./rv.exe smptebars,start=1,end=100,fps=60.movieproc
First set the following env var to 0 to make sure that garbage collection takes place during playback
export RV_DISABLE_GARBAGE_COLLECTION_DURING_PLAYBACK=0
Then you can validate without the env var.
Signed-off-by: Bernard Laberge bernard.laberge@autodesk.com