Skip to content

Conversation

braandl
Copy link
Contributor

@braandl braandl commented Jun 17, 2025

This is another memory-leak that happens within my setup using the java.nio.* implementation. Just like shown in #2501 it creates cyclic reference between the DirectByteBuffer and MemoryRef.

Since the mechanism was created to hold a reference to the original Buffer, after the "live" reference might has been deallocated, this seems not to be a working mechanism in Objective-C.

This change sets the originalBufferObject to always null (like on the other constructor already) to avoid this behavior.
Therefore now the MemoryRef loses its functionality of keeping the DirectByteBuffer's ref. I could not find any negative effects tough, since I am convinced, this can not happen in the transpiled framework anyways.

In the generated code, this results in a cyclic dependency. Since the mechanism was created to hold a reference to the original Buffer, after the "live" reference might has been deallocated, this seems not to be a working mechanism in Objective-C.

This change sets the originalBufferObject to always null (like on the other constructor already) to avoid this behavior. Will need to test for side-effects
Copy link

google-cla bot commented Jun 17, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@braandl
Copy link
Contributor Author

braandl commented Sep 4, 2025

I don't want to be annoying, but in our project, this makes the difference between usable and permanently crashing. Idk how other people experience this, but it might be nice to be merged into upstream?

@tomball
Copy link
Collaborator

tomball commented Sep 4, 2025

Your contribution hasn't been merged because you haven't accepted the Contributor License Agreement: https://github.com/google/j2objc/pull/2508/checks?check_run_id=44243757472. If you did accept the CLA, then that link has debugging steps you should take so the licensing bot gets updated.

If for any reason you can't or don't want to accept the CLA, let me know. I won't be able to merge your change, but can review the problem you raised and fix it independently.

@braandl
Copy link
Contributor Author

braandl commented Sep 7, 2025

I did after I created this. Somehow the bot does not recognize it, but the website states my state is fine.

Copy link
Collaborator

@tomball tomball left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the contribution!

@tomball tomball merged commit 14b0500 into google:master Sep 7, 2025
1 check passed
@tomball
Copy link
Collaborator

tomball commented Sep 7, 2025

Your PR is merged, thanks for your contribution (and patience!).

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

Successfully merging this pull request may close these issues.

2 participants