-
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
Memory leak(s) and PR to fix them #27
Comments
Hello @jezwhite thanks for your questions and comments. I have not used this module in quite some time, so my memory is vague and I may not have (good) answers for some / all of your questions. In general, I will give preference to any PR that includes a test case which fails before the PR (showing the error condition) and which succeeds after the PR. Regarding your specific questions:
Looking forward to any PRs. Cheers! |
Understood. So in this case, it's pure memory leaks. Can you suggest any Test module I can use to check memory usage before call(s) and afterwards that you would be happy for me to use? Or just something simple like https://metacpan.org/pod/Memory::Usage ?
So...yeah, it was harder than I thought once I started looking at the internals:) I had to go simple but I think I have something that is working and passes all tests, but there is an edge case I am unsure of so I still testing/playing.
I will put one together - would you mind giving it look over to see if seems 'ok'? |
I have used Happy to review any proposed PR. Cheers! |
Hello all,
I have come across various minor memory leaks and a major one when using closures. It's been a while since I've used XS and there are things I don't understand so I wanted to run through some of my proposed changes.
Minor leaks - Changes
The first change would be to add a dedicated destructor, something like:
Which would be called in session_dtor. However, I don't understand the line:
static MGVTBL session_magic_vtbl = { .svt_free = session_dtor };
and why all associated magic logic in the typemap? Why isn't a simple destructor used? ie,
There are a couple of other minor leaks, such as reset_msgs and reset_stats but these are simple to fix.
Major Leak - Closures
This is causing me massive problems. The following (contrived) example will highlight the problem when using closures:
I believe the problem is in pl_perl_to_duk_impl, and this line:
func = newSVsv(value);
This newly created SV is never freed, thus the closure can never be either. I think doing a SvREFCNT_inc rather than newSVsv on the code ref SV and dropping it again when the coderef isn't needed solves the problem (it seams to in my basic testing). The change would need to keep track of the coderef and do the appropriate SvREFCNT_dec when the code ref is replaced (->set ). removed (->remove) and when the main duktape object is destroyed.
Thoughts? Comments?
The text was updated successfully, but these errors were encountered: