Skip to content

Code issues #6

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

Closed
amos402 opened this issue Feb 10, 2021 · 3 comments
Closed

Code issues #6

amos402 opened this issue Feb 10, 2021 · 3 comments

Comments

@amos402
Copy link
Member

amos402 commented Feb 10, 2021

var handle = GCHandle.Alloc(domain, GCHandleType.Pinned);

It's not necessary to use pinned, there nowhere used its original structure.

return Marshal.GetFunctionPointerForDelegate(deleg);

deleg is a local variable, once the method returned, it might be collected by GC, after that, the pinter is a dangling one.

@filmor
Copy link
Member

filmor commented Feb 10, 2021

var handle = GCHandle.Alloc(domain, GCHandleType.Pinned);

It's not necessary to use pinned, there nowhere used its original structure.

You are right, I'll fix this to return the GCHandle pointer directly.

return Marshal.GetFunctionPointerForDelegate(deleg);

deleg is a local variable, once the method returned, it might be collected by GC, after that, the pinter is a dangling one.

This is correct as well. I'll probably just add a static dictionary of GCHandle's here, or do you have a better idea?

@amos402
Copy link
Member Author

amos402 commented Feb 10, 2021

Use a dictionary to hold the reference is enough, and it should be cleared after calling CloseAppDomain.

@filmor filmor mentioned this issue Feb 10, 2021
@filmor
Copy link
Member

filmor commented Feb 11, 2021

Fixed by #7.

@filmor filmor closed this as completed Feb 11, 2021
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