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

go开辟空间给c用会内存泄露吗 #8

Open
liliang8858 opened this issue Nov 20, 2018 · 5 comments
Open

go开辟空间给c用会内存泄露吗 #8

liliang8858 opened this issue Nov 20, 2018 · 5 comments

Comments

@liliang8858
Copy link

No description provided.

@chai2010
Copy link
Owner

要分场景。如果是Go的切片内容传人C函数临时使用,C函数返回前是安全的。如果C函数返回后被其它C函数引用,那么因为GC可能导致Go内存被移动,因此这种C函数的引用是错误的。如果是调用C函数的malloc,那么就是传统C语言管理内存的模式。

@liliang8858
Copy link
Author

如果 c函数返回 拷贝一份,还可以继续传入下个c函数用吗? @chai2010

@chai2010
Copy link
Owner

如果是C语言分配的内存空间,任何时刻都可以再传给C函数使用

@liliang8858
Copy link
Author

有可能被 go 给gc掉吗?

@chai2010
Copy link
Owner

C分配的内存,gc不会释放。
Go自己分配的指针,好像都是有标记的。

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