什么是固定对象? [英] What are pinned objects?

查看:20
本文介绍了什么是固定对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ants 内存分析器查找内存泄漏,并且我遇到了一个新术语:

I am trying to find a memory leak using ants memory profiler, and I've encountered in a new term:

固定对象.

有人能给我一个好的&简单解释这个对象是什么,我如何固定/取消固定对象,并检测谁固定对象?

Can some one give me a good & simple explanation about what this objects are, How can I pinn/Unpinn objects, and detect who pinned objects?

谢谢

推荐答案

固定对象是不允许移动的对象.垃圾收集器通常会压缩内存,因为它将所有对象移动到一个或多个集群".这是为了创建大块的可用空间.

A pinned object is one that is not allowed to move. The garbage collector is normally compacting the memory in that it moves all objects to "one or more clusters". This is to create large chunks of free space.

这基本上意味着如果其他人(外部)有一个指向对象内存地址的指针,这可能指向随机内容 - 随着对象移动.

This basically means if someone else (outside) has a pointer to the memory address of an object, this may point to random content - as the object has moved.

固定一个对象告诉 GC 不要移动它.这通常是无用的,只有在使用指针时才有意义 - 就像使用 PInvoke 时一样.有时您需要将地址转换为结构(在内存布局术语中),如果这是在类中实现的,则必须将其固定.

Pinning an object tells the GC to NOT MOVE IT. This is normally useless and ONLY makes sense when working with pointers - like when using PInvoke. Sometimes you need to turn in an address to a structure (in the memory layout term), and if that is implemented in a class, you have to pin that.

具体回答:

  • 你无法找出谁固定了一个对象.
  • 固定是通过 FIXED 语句完成的.这仅在不安全代码中允许.

检查:

http://msdn.microsoft.com/en-us/library/f58wzh21%28VS.80%29.aspx

这篇关于什么是固定对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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