create_sprite_from_surface causing FPS drops and memory leaks

Hello! I'm working with a code base that uses create_sprite_from_surface() to do a "reflective water" effect.

This code create eight sprites from the bottom of application_surface and then draws them in reverse order, offsetting them to create the water effect.

The problem is that even though the eight sprites are being deleted properly, the eight calls to create_sprite_from_surface() on a per-update basis is causing a memory leak, and every call to create_sprite_from_surface() takes a little longer, meaning the game eventually starts to have frame rate problems.

I'm aware that the debugger can cause memory leaks, but this is happening with a YYC build on target hardware.

Since the sprites never change shape (just the data they contain) is there some way to create them once and then re-use them? Or is there a clearly better way to do this that I'm missing?

Thank you very much for any help you can give.


Another way to create water reflections is a shader. Since your reflections sound like rectangular regions it might suit your use case.