Marshal.Release(IntPtr) 메서드

정의

지정된 인터페이스의 참조 횟수를 감소시킵니다.

public:
 static int Release(IntPtr pUnk);
[System.Security.SecurityCritical]
public static int Release (IntPtr pUnk);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static int Release (IntPtr pUnk);
public static int Release (IntPtr pUnk);
[<System.Security.SecurityCritical>]
static member Release : nativeint -> int
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member Release : nativeint -> int
static member Release : nativeint -> int
Public Shared Function Release (pUnk As IntPtr) As Integer

매개 변수

pUnk
IntPtr

nativeint

해제할 인터페이스입니다.

반환

pUnk 매개 변수에서 지정하는 인터페이스에 대한 참조 횟수의 새 값입니다.

특성

예제

다음 예제에서는 메서드를 사용 하 여 관리 되는 IUnknown 개체에 대 한 인터페이스를 검색 하는 방법을 보여 줍니다 GetIUnknownForObject . 그런 다음, 메서드를 호출하여 인터페이스 포인터를 해제합니다 Release .

using System;
using System.Runtime.InteropServices;

class Program
{

    static void Run()
    {

        // Create an int object
        int obj = 1;

        Console.WriteLine("Calling Marshal.GetIUnknownForObject...");

        // Get the IUnKnown pointer for the Integer object
        IntPtr pointer = Marshal.GetIUnknownForObject(obj);

        Console.WriteLine("Calling Marshal.Release...");

        // Always call Marshal.Release to decrement the reference count.
        Marshal.Release(pointer);
    }

    static void Main(string[] args)
    {
        Run();
    }
}
Imports System.Runtime.InteropServices

Module Program


    Sub Run()

        ' Dim an Integer object
        Dim IntegerObject As Integer = 1

        ' Dim a pointer
        Dim pointer As IntPtr

        Console.WriteLine("Calling Marshal.GetIUnknownForObject...")

        ' Get the IUnKnown pointer for the Integer object
        pointer = Marshal.GetIUnknownForObject(IntegerObject)

        Console.WriteLine("Calling Marshal.Release...")

        ' Always call Marshal.Release to decrement the reference count.
        Marshal.Release(pointer)



    End Sub

    Sub Main(ByVal args() As String)

        Run()

    End Sub

End Module

설명

공용 언어 런타임은 COM 개체의 참조 수를 관리하므로 이 메서드를 직접 사용할 필요가 없습니다. 이 값은 테스트 목적으로만 사용합니다. 사용자 지정 마샬러 테스트와 같은 드문 경우에서는 개체의 수명을 수동으로 조작해야 할 수 있습니다. 를 호출 Marshal.AddRef 하는 프로그램만 을 호출 Release해야 합니다. 참조 수가 0에 도달한 후 를 호출 Release 하면 정의되지 않은 동작이 발생합니다.

, 또는 Marshal.GetIDispatchForObjectMarshal.GetIUnknownForObject호출Marshal.GetComInterfaceForObject하여 해제할 IUnknown 인터페이스 포인터를 나타내는 값을 가져올 IntPtr 수 있습니다. 관리되는 개체에서 이러한 메서드와 메서드를 Release 사용하여 관리되는 개체의 COM 호출 가능 래퍼가 나타내는 COM 인터페이스를 해제할 수도 있습니다.

적용 대상

추가 정보