Why does not skia remove created textures?

40 views
Skip to first unread message

Данил Буланов

unread,
Jul 24, 2024, 3:43:42 PM (3 days ago) Jul 24
to skia-discuss
Demo link: https://jsfiddle.net/5c7dwszt/5/

I have a demo, where I create a buch of images on button "Make images", in the console there are logs for each texture creation, I create 1000 images using this code

const surf = canvas.makeSurface({
width: 500,
height: 500,
alphaType: CanvasKit.AlphaType.Premul,
colorSpace: CanvasKit.ColorSpace.SRGB,
colorType: CanvasKit.ColorType.RGBA_8888,
});
surf.flush();
const image = surf.makeImageSnapshot();
setTimeout(() => {
image.delete();
}, 10);
surf.delete();

I delete each surface as well as each image, so I expect that such code would use memory only during execution, but my expirements say the opposite:
When I click "Make images" my OS memory profiler shows memory increase, then memory decreases, but not to the same level as it was in the beginning. Also, my logs for texture creation/deletion say that there are 268 textures left undeleted. When I trigger releaseResourcesAndAbandonContext it frees the rest of the textures.

So my question is does skia have some kind of cache of images? Even though I cant imagine how to use such a cache.

It is very critical for me, because in my example these 268 textures use about 300mb of memory (according to my memoty profiler).

Brian Osman

unread,
Jul 25, 2024, 2:28:20 PM (2 days ago) Jul 25
to skia-d...@googlegroups.com
Yes, the GPU backend does maintain a cache of texture / framebuffer objects. This is mostly because creating and deleting resources can be expensive (especially on OpenGL). When you delete them, they get returned to the cache - they're not reused as "that particular image", but they are reused when a new image of the same size is created, or for temporary storage of things like saveLayer. You can change the size of that cache with an API on the GrDirectContext: `context.setResourceCacheLimitBytes()`

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/56f9d361-90ab-4b09-988c-6fa27815f397n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages