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

[cgo] unloadLibrary is never called #133

Open
alexanderoster opened this issue Jul 28, 2020 · 3 comments
Open

[cgo] unloadLibrary is never called #133

alexanderoster opened this issue Jul 28, 2020 · 3 comments

Comments

@alexanderoster
Copy link

We would need to call unload library with the wrapper destructor, but I am a bit helpless how this works. @qmuntal: Is there a chance you can take a look at this?

@qmuntal
Copy link

qmuntal commented Jul 28, 2020

I don´t think it make sense to add the auto-release capability to the wrapper. It clearly a resource loaded by the user, therefore it should be unloaded by the user, same as when opening/closing files or http requests.

I would just add a Unload method to the Wrapper struct that performs the unloading.

@alexanderoster
Copy link
Author

I see, thank you for the feedback!
But does that mean the unload will leak memory if the wrapper goes out of scope?

@qmuntal
Copy link

qmuntal commented Jul 28, 2020

But does that mean the unload will leak memory if the wrapper goes out of scope?

Yes, unless the user calls unload before the wrapper goes out of scope. defer is very helpful in this scenarios:

lib := act.LoadLibrary("C:/foo.dll")
defer lib.Unload() // lib will be automatically released when going out of scope

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

No branches or pull requests

2 participants