-
Notifications
You must be signed in to change notification settings - Fork 5
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
Potential memory leak #4
Comments
Thanks @Manfred. Yeah I'm able to reproduce that on M1 Crystal 1.8.2. My findings as below: Image size: 3.4M Crystal uses bdwgc as its GC. I notice that GC cleanup is performed in the end. Might be due to the fact that we are invoking operation in a tight loop and GC doesn't get a chance to tick. Adding a small pause in loop keep the mem usage to some low value (around 100M). I will try to dig deeper to see if there something which can be further optimized. |
I'm not sure if it's just garbage collection, because it doesn't improve when you call I tried the following:
And this gives me roughly the following output:
Any time you can spend on this is appreciated! |
@Manfred pushed changes to fix memory usage issue. After fix, running your provided sample yields following output on my box. Please make sure you run Resident memory usage: 34.5 megabytes
Resident memory usage: 35.2 megabytes
Resident memory usage: 35.4 megabytes
Resident memory usage: 35.5 megabytes
Resident memory usage: 35.6 megabytes
Resident memory usage: 35.7 megabytes
Resident memory usage: 35.7 megabytes
Resident memory usage: 35.7 megabytes
Resident memory usage: 35.8 megabytes
Resident memory usage: 35.8 megabytes
Resident memory usage: 35.8 megabytes
Resident memory usage: 35.8 megabytes
Resident memory usage: 35.8 megabytes |
That fixes the specific issue for me too, but when I add some operations the leaking comes back, for example:
|
Fixed and pushed changes. Please let me know if you are getting different results. |
Yeah, that definitely fixes it. Thanks! |
When I run
crystal leak_test.cr
with any file I see the the process grow to use gigabytes of memory. This happens both on Crystal 1.7.3 as well as Crystal 1.8.2.I verified that this happens on macOS Venture on both and M1 and an Intel processor. I also verified that it happens on Ubuntu on an Intel processor. Finally I verified that it's not a Vips issue by porting
leak_test.cr
to Ruby and test with the Ruby bindings and there the memory usage stays below 70 megabytes.I'm not really familiar with how memory management is supposed to be implemented for Vips bindings, so I don't know where to start looking for a solution.
The text was updated successfully, but these errors were encountered: