从内存在C#中释放的指针 [英] Freeing a pointer from memory in c#

查看:1025
本文介绍了从内存在C#中释放的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用固定{} 短语处理指针在C#。

I'm dealing with pointer in C# using fixed{} phrases.

我把里面我的代码固定语句的支架,想知道如果垃圾收集将固定的语句

I placed my code inside the brackets of the fixed statement and want to know if the Garbage collection will handle the pointer freeing after the fixed statement

fixed{int * p=&x}
{
// i work with x.
}

如果不是我怎么能释放呢?

if not how can I free it?

推荐答案

您的指针指向一个管理对象( X ),所以没有什么可担心的:指针并不需要被释放(或者更确切地说,它在固定块的末尾超出范围)和指针 X 本身由GC管理

Your pointer points to a managed object (x) so there is nothing to worry about: the pointer does not need to be freed (or rather, it goes out of scope at the end of the fixed block) and the pointee x itself is managed by the GC.

这篇关于从内存在C#中释放的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆