pathfinder icon indicating copy to clipboard operation
pathfinder copied to clipboard

Memory leak in C API Binding

Open VijithK opened this issue 4 years ago • 6 comments

I am using C API binding for text rendering in Qt. I need to continuously render with different/same text.

Current implementation: On every frame update I call PFSceneProxyBuildAndRenderGL with same PFGLRendererRef and PFBuildOptionsRef. After every render I call PFSceneProxyDestroy assuming that it destroys scene_proxy(PFSceneProxyRef), scene(PFSceneRef) and canvas(PFCanvasRef). I initialize scene, proxy, canvas again. It looked expensive in terms of processing and memory to use new renderer on every update.

My Issue: I see memory leak somewhere, memory is constantly growing until application becomes unresponsive.

Am I missing something obvious?

Here is sample:

In my render(): PFSceneProxyBuildAndRenderGL(scene_proxy, renderer, option);

All of the parameters are global here. Before next render I do this:

PFSceneProxyDestroy(scene_proxy);
PFCanvasSetFontByPostScriptName(textCanvas, "Dosis-ExtraBold", 15);
PFCanvasSetFontSize(textCanvas, 32.0);
style = PFFillStyleCreateColor(&color);
PFCanvasSetFillStyle(textCanvas, style);
PFCanvasFillText(textCanvas, str, str.length(), &pos);
scene = PFCanvasCreateScene(textCanvas);
scene_proxy = PFSceneProxyCreateFromSceneAndRayonExecutor(scene);
render();

VijithK avatar Mar 16 '20 11:03 VijithK

This may be fixed now in 32a56ea. Please try again.

pcwalton avatar Apr 01 '20 00:04 pcwalton

I tried this, I still see the memory growing on every update.

VijithK avatar Apr 01 '20 11:04 VijithK

I have the same issue, compiling for Windows 10, 64 bit. Allocated data grows every frame. However I've been able to determine that the memory leak has something to do with the timer queries in the Renderer struct, as commenting out self.end_composite_timer_query(); self.pending_timers.push_back(mem::replace(&mut self.current_timers, RenderTimers::new())); and self.device.end_timer_query(&timer_query); self.current_timers.stage_0.push(timer_query); from Renderer::draw_buffered_fills

self.begin_composite_timer_query(); from Renderer::render_command

and self.end_composite_timer_query(); self.pending_timers.push_back(mem::replace(&mut self.current_timers, RenderTimers::new())); from Renderer::end_scene fixes the memory leak.

ghost avatar Apr 06 '20 19:04 ghost

@BenGachowski reverted to eb2b62261553a1154d9c97ce9cb0f681a1de1659 and commented above mentioned lines. I still see memory leak.

VijithK avatar Apr 20 '20 06:04 VijithK

There does appear to still be a memory leak in the c binding function PFCanvasSetFontByPostScriptName. The other timer related memory leak appears to have been fixed by commit 47919db8f35ca3401bea35ce02fa0a8215ed26a9

edit: While the State struct does get dropped, somehow data related to the FontCollection is not released. I see lots of allocations from font-kit and directwrite that never get freed.

ghost avatar Apr 22 '20 04:04 ghost

I had issues running my Qt application with the most recent commit. I started fresh with building demo application, I initially got https://github.com/servo/pathfinder/issues/276 issue as I was on Windows. Later I tried to build c_canvas_minimal(wrote a separate Makefile) it builds fine, but when I run the application it fails silently just the way it was failing in my Qt application.

Edit: c_canvas_minimal fails after this https://github.com/servo/pathfinder/commit/895f73096ec84929f402aed20b63bd0a47c3529c commit.

VijithK avatar Apr 30 '20 15:04 VijithK