I noticed that the memory usage of my application keeps increasing the more I use the Paragraph class.
using namespace std;
using namespace skia::textlayout;
int main()
{
if (!SkLoadICU()) return -1;
auto surface = SkSurface::MakeRasterN32Premul(1920, 1080);
auto canvas = surface->getCanvas();
for (size_t i = 0; i < 10000; i++)
{
canvas->clear(SK_ColorWHITE);
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorBLACK);
TextStyle textStyle;
textStyle.setForegroundColor(paint);
textStyle.setFontFamilies({ SkString("Roboto") });
auto fontCollection = sk_make_sp<FontCollection>();
fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
ParagraphStyle paragraphStyle;
paragraphStyle.setTextStyle(textStyle);
ParagraphBuilderImpl builder(paragraphStyle, fontCollection);
builder.addText("Text");
auto paragraph = builder.Build();
paragraph->layout(100);
paragraph->paint(canvas, 0, 0);
//used to add a delay so I can monitor memory usage
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
return 0;
}
So, running the code above will show memory usage increasing and never decreases, so I suspect that there are memory not being released. If I don't call paragraph->layout(100) then the memory usage remains stable but of course it doesn't render the text. Does anybody know how to solve this? Do I need to release anything manually?