-
Notifications
You must be signed in to change notification settings - Fork 24
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 Python target fixed #246
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic! Some minor suggestions included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I left some minor comments...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the lingering comments, this looks good to me. I like that it hooks the reference count into our destructor mechanism -- this seems like the right way to get our memory management system to interact properly with CPython's. As before, I'm really grateful that I didn't have to do this because this looks really hard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not merge this yet because there are test failures; see the discussion at lf-lang/lingua-franca#1873
Co-authored-by: Edward A. Lee <[email protected]>
It was incorporated to assist with debugging.
Co-authored-by: Edward A. Lee <[email protected]>
Co-authored-by: Edward A. Lee <[email protected]>
Co-authored-by: Marten Lohstroh <[email protected]>
Co-authored-by: Marten Lohstroh <[email protected]>
The function is called by the deserializer during federated execution.
This commit fixes segfault for unfederated execution, but leads to memory leak during federated execution.
df0379b
to
d28a9f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests seem to be passing without a segfault in the companion PR, and the most problematic memory leak seems to be fixed. I think this is ready to merge (as soon as the companion PR can also be merged).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 🚀 🚀
This pull request addresses a memory leak issue observed in the current implementation. As shown in the following screenshot, it is noticeable that with each iteration, the size of Python objects constructed using C extensions continues to grow.
This problem could be attributed to several key issues, which are as follows:
PyObject Reference Count: The reference counts for the majority of
PyObjects
are not being appropriately managed.Port Assignment: Rather than using the
_LF_SET
macro to assign values to thegeneric_port_instance_struct
in the current implementation, the more suitable method would be to uself_set_token
and define a destructor for the token to ensure proper garbage collection.Function Definition: The existing
_lf_free_token_value
function is incorrect and fails to invoke the destructor.Comments have been added to the code within the commits to provide additional context and insight into the changes made. Other related changes have also been made in the code generator repository (LINK).
Please feel free to comment if further modifications are required. Similar issues persist during the federated multiport setting. To address this, a separate PR will be submitted later.