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 libpostal libpostal_parse_address method #1407

Open
orividrisk opened this issue Aug 27, 2023 · 6 comments
Open

Memory leak in libpostal libpostal_parse_address method #1407

orividrisk opened this issue Aug 27, 2023 · 6 comments

Comments

@orividrisk
Copy link

Hi,
When using the libpostal 1.1-1.5.8 I experience a memory leak in my java process.
My code is iterating on a large number of addresses, and over time the java process memory is increasing until it crashes due to OOM.
I have monitored the jvm heap and non heap memory metrics and there is no issue there.
This leads me to the conclusion that the issue is with the native allocation of the returned address response, which is not deallocating the parsed addresses.
I did some debugging and found that the libpostal_address_parser_response_t object does not contain a deallocator, which if I understand correctly is in charge of deallocating the response object ( see in image).

The following is my code (I am using the default options provided by the library):


try (PointerScope pointerScope = new PointerScope();
             libpostal_address_parser_response_t response = libpostal_parse_address(addressStr, options)) {

            long count = response.num_components();
            Map<String, String> fields = new HashMap<>();

            for (int i = 0; i < count; i++) {
                fields.put(response.labels(i).getString(), response.components(i).getString());
            }

            libpostal_address_parser_response_destroy(response);
            return fields;
 }

image

I would very appreciate your prompt assistance with the issue as it is having a big impact on our production env.
Thank you and have a very nice day.

@saudet
Copy link
Member

saudet commented Aug 27, 2023 via email

@orividrisk
Copy link
Author

orividrisk commented Aug 27, 2023

@saudet Thank you for the prompt response!

How can we verify if the issue is with libpostal or with the javacpp-presets?
When calling the libpostal_parse_address method which one is responsible for creating the deallocator object?

@saudet
Copy link
Member

saudet commented Aug 27, 2023 via email

@orividrisk
Copy link
Author

orividrisk commented Aug 27, 2023

Just to verify, does that mean that every native method returning an object which inherits from org.bytedeco.javacpp.Pointer ( in this case: libpostal_address_parser_response_t) will not have a deallocator?
If that is the case is the expectation that libpostal will both return the result of the native method called, and deallocate the memory used to create the return type instance in a synchronous manner?

@saudet
Copy link
Member

saudet commented Aug 27, 2023 via email

@orividrisk
Copy link
Author

I understand, thank you.
I opened an issue in the upstream repo: openvenues/libpostal#641
Waiting for their response

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

No branches or pull requests

2 participants