Skip to content

Conversation

FrancisDuvivierTHEO
Copy link
Contributor

Description

This PR is for fixing a memory leak which is caused by passing java objects to the javascript runtime. This memory leak is small, but with a lot of objects passed, it is certainly measurable. From our measurements. Every java object passed to javascript adds about 85bytes to the native memory which never gets cleaned up even if the object is garbage collected on both sides.
We found the native objects causing this leak and deleted them on finalization.

Does your commit message include the wording below to reference a specific issue in this repo?

No there is no issue for it in the repo currently

Related Pull Requests

None

Does your pull request have [unit tests]

No, this kind of memory leak is not unit-testable from java or javascript as far as I can tell.
Setting up a cpp unit test suite for this would be overkill.

This fixes a small memory leak from java objects being passed from java to javascript and then being garbage collected
This fixes a small memory leak from java objects being passed from java to javascript and then being garbage collected
@cla-bot
Copy link

cla-bot bot commented Jan 17, 2020

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign the CLA at https://www.nativescript.org/cla.
CLA has not been signed by users: @FrancisDuvivierTHEO.
After signing the CLA, you can ask me to recheck this PR by posting @cla-bot check as a comment to the PR.

po->Get(m_isolate)->SetInternalField(jsInfoIdx, Undefined(m_isolate));
po->Reset();
auto it = m_idToObject.find(javaObjectID);
m_idToObject.erase(it);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be easier and safer to directly m_idToObject.erase(javaObjectID); here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Does your team prefer this commit to be modified (rebase with a fixup) or an extra commit?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra commit should do it, thanks.

m_idToObject.erase(it);
delete po;
delete callbackState;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks, we'll add that.

@vtrifonov
Copy link
Contributor

@FrancisDuvivierTHEO could you, please, sign the CLA here - https://www.nativescript.org/cla.

@cla-bot cla-bot bot added the cla: yes label Jan 21, 2020
@darind darind merged commit 6bd3ba9 into NativeScript:master Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants