Hi, I've been using Skia (OpenGL backend) in my project and I've run into a high memory usage problem. My app needs to display ink strokes (ala OneNote) and the user is able to scale the ink strokes using pinch zoom or their mouse wheel.
To draw the paths, in each frame I construct a SkPath (a filled polyline) for each stroke, scale the canvas, draw and flush. The problem is that if the user pinches in and out continuously, the app results in an almost ever growing usage of memory. Profiling in Visual Studio, having a single filled SkPath on the canvas and scaling the canvas each frame by pinching in and out, my app can easily exceeds 400-500 Mb of memory used. The bigger issue is that this memory is not immediately released on the next frame (it seems that to (slowly) release it I have to render the frame again with no draw commands for an extended period of time or commands that do not draw the same path).
I assume this is because Skia does some sort of caching of paths (at each scale I assume) and "cleverly" reuse them if needed, however I need the memory footprint to be low as at any moment in time I can
have hundrededs of strokes on the screen.
What I've tried so far without success:
- Use SkPath::reset() after I draw the path
- GrDirectContext::setResourceCacheLimit(10000)
- Calling GrDirectContext::freeGpuResources() at the end of each frame.
Any suggestions to mitigate this would be appreciated.