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

Ensure that the device pointer we get from getConnectedDevicePointer is released when no longer used #21539

Open
tehampson opened this issue Aug 2, 2022 · 4 comments
Assignees
Labels

Comments

@tehampson
Copy link
Contributor

Problem

With #21256 we are introducing a memory leak. The leak was allowed to be introduced since that PR fixes a use after free that is arguably worse then the memory leak. The PR was large enough without refactoring the java side hence creating this PR so that the memory leak could be addressed separately afterwards

Proposed Solution

When onDeviceConnected gives a pointer to the Java side. We wrap the pointer in an object that has a desctructor that calls a JNI to do a free on that pointer provided. This would need all downstream consumers that previously passed a long the pointer to now use the wrapper object.

@tehampson tehampson self-assigned this Aug 2, 2022
@stale
Copy link

stale bot commented Feb 4, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@yunhanw-google
Copy link
Contributor

is this still issue? @tehampson

@maurycyw
Copy link

I don't understand why using something like try { ... get and use pointer } finally { releasePointer } is not a viable solution. (Especially since folks can create helpers if needed unless this is meant to track that work)

@yunhanw-google this is still present within the android chiptool project.

@tehampson
Copy link
Contributor Author

tehampson commented Mar 25, 2024

If I remember this issue correctly. The problem is that the onDeviceConnected is called back from the Matter SDK event loop thread, and it uses this callback here to provide an OperationalDeviceProxy.

If I recall correctly, on the android side the act of connecting and the act of doing some interaction are 2 separate paths. The result of the connection provides the pointer to the OperationalDeviceProxy. It was this pointer, that at the time, was not being freed properly after the interaction was completed.

Could something like you suggested be done, it seems likely. But it might need a little bit of a rework to bring the connecting and doing the interaction into that try block.

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

No branches or pull requests

3 participants