-
Notifications
You must be signed in to change notification settings - Fork 80
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 in polygonToCells #168
Comments
Thanks for a really detailed bug report. This does sound like a library issue, though unclear whether the issue is in the wrapper code or the transpiled library. I'll try to reproduce on my end. |
I appreciate your prompt response. I can provide you with some code if it helps debug the issue further. |
@nrabinowitz did you manage to have a look at this issue? I am double-checking my code, but still encountering the same problem with version 4.1.0 of h3-js. Appreciate any update. Thanks. |
Sorry, haven't had a chance to look yet. I'll try to find time this week. |
@nrabinowitz I have written separate code to reproduce the issue (running under Node.js v20.6.0). This simple script logs the memory usage as the number of calls made to
First grid square passes with memory usage: Second grid square passes with memory usage: Third grid square fails:
(Note the |
After some further testing, calling |
Thanks for the repro script - looking now |
I can repro the issue with your script. Just to document my understanding so far:
So... possibly it's the memory allocated for the polygon, which isn't getting freed properly? I'll continue to investigate. |
I think this may simply be because the coarse resolutions run faster, and so you get to |
New observation: The number of calls required to get to OOM varies inversely with the size of the polygon - a more complex polygon with 65 vertexes failed in only 1.9M calls (vs the updated, I think correct number of 20M for the 4-vertex bbox). That suggests strongly that it's the polygon that isn't being deallocated correctly, and specifically the vertex loop. The polygon is also much more complicated to deallocate, so that tracks, but I'm going to need to investigate further to see if I can find what's going wrong. |
I am processing image files into h3 cells which convert a bounding box for each pixel in the Geo TIFF file into h3 cells at the specified resolution (in this case res 10). The code works perfectly for a while, but after a certain amount of processing memory errors occur.
For example, with these bounds:
E -69.36043436899354, W -69.36251770199354, N 81.41166741399798, S 81.40958408099797
this error is eventually thrown AFTER a large number of bounding boxes, at the same size / resolution, have been successfully processed:
Similarly:
E -69.35835103599354, W -69.36043436899354, N 81.41166741399798, S 81.40958408099797
Here's an extract from the code that fails:
The code starts to fail after around c. 10-20 millions calls to
polygonToCells
. Note the same issue happens with both versions 3 and 4 of the library.Encountering the issue with Node v 17.8.0, on both Intel and Apple Silicon Macs.
The text was updated successfully, but these errors were encountered: