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

add PLGNFreeCString(str *C.char) to free the memory allocated by Golang using C.CString() #73

Closed
wants to merge 3 commits into from

Conversation

yushihang
Copy link
Contributor

@yushihang yushihang commented Apr 3, 2024

close #72

@olomix
Copy link
Contributor

olomix commented Apr 4, 2024

Sorry, maybe I'm missing something, but what is the purpose of wrapping the free function in Go's PLGNFreeCString? Why not call it directly?

For now, I don't see any rationale for adding this function.

@yushihang
Copy link
Contributor Author

yushihang commented Apr 5, 2024

Hi @olomix,

Thanks for you response.

Since this PR involves two repositories, I have written a more detailed response in the PR for polygonid-flutter-sdk here: 0xPolygonID/polygonid-flutter-sdk#390 (comment).

In my understanding, PLGNFreeCString() does not only provide a C.free() function for Flutter, but it should be understood as follows:

  1. Since the memory is allocated from the OS by Golang, Flutter does not release it directly.
  2. Flutter/Dart calls PLGNFreeCString() to inform Golang that the memory block that Golang allocated will not be used anymore by Flutter/Dart.
  3. Golang can handle this memory block subsequently. (Golang can then free the memory block by calling free(), or manage the memory block in other ways.)

@OBrezhniev OBrezhniev requested a review from olomix April 9, 2024 22:55
@yushihang yushihang closed this Apr 30, 2024
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.

Memory allocated in Golang by C.CString() should be freed
2 participants