-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] Why memory grows when destroying and recreate fonts object? A better approach to change fonts and styles on runtime? #12
Comments
I can see that ofxFontStash has this '= NULL', what seems like a destroyer:
So maybe I need to call this destroy/ 'delete' in some way?
I tried around this without success:
Any idea of how can handle this? |
Note that for Fontstash2, a single object can hold N fonts and styles, so you should be ok creating a single object only and adding multiple fonts to it. ofxFontStash can do that but its not so ready/built with that mindset, so I usually create on object per font. Now, if your styles change over time as the app is running, you will need to load fonts on the fly. Do you now know the styles you will need before the app is launch? Loading fonts is also quite expensive and will likely make your framerate drop. If possible, I would try to pre-load all the styles in setup. As for memory growing quickly, it likely means there's a leak on the ofxFontstash2 destructor, and I should have a look. Because of the nature of fonts inside interactive apps, I never had to destroy ofxFontStash2 objects directly so the destructor is likely untested, and it may indeed be leaking. About your tests on forcing a memory release, you shouldn't have to force a destructor call, or ever call directly a destructor. When you do ...
... the destructor for "fonts" (ofxFontStash2::~Fonts()) is executed. It should cleanup all the resources allocated when constructing the object. If it doesn't, a memory leak occurs, and this is likely what's happening. For ofxFontStash2 I would recommend you don't delete the ofxFontStash2::Fonts object though, you should just add new fonts to the same object as you need them. Creating and destroying the nvg context is probably an expensive operation. For your case I see there's no way to remove fonts once added (sorry, ofxFontStash2 is quite unfinished) so you could look into implementing one. about the |
Thanks a lot for your detailed reply. I'll look deeper into, |
Hey @armadillu ,
I want to change the added fonts and styles (to the ofxFontStash2::Fonts object) on the fly.
I am trying to use your tip (armadillu/ofxFontStash#29) about destroying the object also with ofxFonStah2:
But the memory used by the app is growing very fast (looked into macOS/Activity Monitor). (like from 100MB to 10GB in some minutes)
(I verified that if I do not refresh the fonts, memory do not grows at all.)
This is my refresh method to change the fonts and styles:
The only 'rare' log I can see is:
When I try to debug if there are too many fonts or styles added to the object on refresh, I can see that the object has just the 4 expected fonts and styles:
(I am using ofxFontStash too in the same project)
The text was updated successfully, but these errors were encountered: