Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in SDL2 build #1364

Open
sbenitezb opened this issue May 12, 2024 · 7 comments
Open

Memory leak in SDL2 build #1364

sbenitezb opened this issue May 12, 2024 · 7 comments

Comments

@sbenitezb
Copy link

I compiled Lem from source on macOS/ARM and there appears to be a memory leak, as the running image grows continuously above 1GB.

@BierLiebHaber
Copy link
Contributor

Does it grow on it's own?
I just tried it and for me it only grows when I scroll in a text buffer.
According to (room) lisp doesn't know about the growth.
I'm guessing some of the textures aren't being freed properly.

@sbenitezb
Copy link
Author

I left it over night and didn't grow a lot, to 1GB. But if I scroll, yeah it jumps by around 100MB. Most of it seems to be released often, but not all, and so it will start accumulating over time.

@BierLiebHaber
Copy link
Contributor

BierLiebHaber commented May 14, 2024

It might not be a leak after all. 🤔
Can you try (lem-sdl2/text-surface-cache:clear-text-surface-cache) when the memory usage is high?
For me it reclaimed most of the memory.
Edit: I tried again after a while and it doesn't seem to reclaim all of it

@BierLiebHaber
Copy link
Contributor

I managed to get memory usage up to 5GB by opening micros.lisp then pressing and holding the right arrow key until I reached the end of the file.

@BierLiebHaber
Copy link
Contributor

BierLiebHaber commented May 21, 2024

After disabling the text-surface-cache I retried moving through micros.lisp and the memory footprint stayed below 600MB.
I disabled the cache by adding #+() to

(push (make-cache-entry
:type type
:attribute attribute
:surface surface)
(gethash string *text-surface-cache*)))

What's the reason for the surface-cache anyways? Rendering doesn't seem slower without it and it causes problems when it gets really big (backspace with a big cache feels unresponsive). At the very least there should be something cleaning up old entries so it doesn't grow to a ridiculous size.

Edit: interestingly clearing the cache while going though the file doesn't seem to have the same effect

@cxxxr
Copy link
Member

cxxxr commented May 22, 2024

Thank you for your research.
It is true that this cache is not very useful.
I remember that when I was drawing characters one by one, the process of creating the surface was very slow and I implemented this cache.
But, the current situation is that the surface is created in larger units, so the effect may be lost.

@BierLiebHaber
Copy link
Contributor

according to #1255 we are still creating 1 surface per character if line-wrapping is disabled, correct?
If that's the case, then cache is probably still useful.

A compromise might be to either only enable the cache if line-wrapping is disabled, or only enable the cache for small strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants