我知道Dispose()用于非托管资源,并且在不再需要资源时不应该等待垃圾收集器完成对象.
但是,在处理对象时,它会抑制垃圾收集器的完成(GC.SuppressFinalize(this);在下面的代码中).这意味着如果对象包含托管资源,我们也必须照顾它,因为垃圾收集器不会清理它.
在下面的示例代码中(来自MSDN),"Component"是一个托管资源,我们为此资源调用dispose()(component.Dispose()).我的问题是,我们如何为作为托管资源的Component类实现此方法?我们应该使用像Collect()这样的东西来捅垃圾收集器来清理这部分吗?
任何想法将不胜感激.谢谢.
以下是我正在查看的代码来自MSDN:
using System;
using System.ComponentModel;
// The following example demonstrates how to create
// a resource class that implements the IDisposable interface
// and the IDisposable.Dispose method.
public class DisposeExample
{
// A base class that implements IDisposable.
// By implementing IDisposable, you are announcing that
// instances of this type allocate scarce resources.
public class MyResource: IDisposable
{
// Pointer to an external unmanaged resource.
private IntPtr handle;
// Other managed resource this class uses. …Run Code Online (Sandbox Code Playgroud) 我已经为我的文本字段禁用了自动更正类型,它没有显示任何其他自动更正,
但是当我按两次空格键时它仍然会自动创建一个点 (.)。
例如,如果我写“test”并按两次空格键,它会自动变为“test”。
有人知道如何禁用此功能吗?
非常感谢。
.net ×1
autocomplete ×1
autocorrect ×1
c# ×1
cocoa-touch ×1
dispose ×1
iphone ×1
resources ×1
sdk ×1