Region.Dispose 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
에서 Region사용하는 모든 리소스를 해제합니다.
public:
virtual void Dispose();
public void Dispose();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
구현
예제
다음 코드 예제에서는 생성자 및 메서드를 ExcludeDispose 보여 Region 줍니다.
이 예제는 Windows Forms와 함께 사용하도록 설계되었습니다. 폼에 코드를 붙여넣고 양식의 FillRegionExcludingPath 이벤트를 처리할 때 메서드를 호출 Paint 하여 다음과 같이 e전달 PaintEventArgs 합니다.
private:
void FillRegionExcludingPath( PaintEventArgs^ e )
{
// Create the region using a rectangle.
System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( Rectangle(20,20,100,100) );
// Create the GraphicsPath.
System::Drawing::Drawing2D::GraphicsPath^ path = gcnew System::Drawing::Drawing2D::GraphicsPath;
// Add a circle to the graphics path.
path->AddEllipse( 50, 50, 25, 25 );
// Exclude the circle from the region.
myRegion->Exclude( path );
// Retrieve a Graphics object from the form.
Graphics^ formGraphics = e->Graphics;
// Fill the region in blue.
formGraphics->FillRegion( Brushes::Blue, myRegion );
// Dispose of the path and region objects.
delete path;
delete myRegion;
}
private void FillRegionExcludingPath(PaintEventArgs e)
{
// Create the region using a rectangle.
Region myRegion = new Region(new Rectangle(20, 20, 100, 100));
// Create the GraphicsPath.
System.Drawing.Drawing2D.GraphicsPath path =
new System.Drawing.Drawing2D.GraphicsPath();
// Add a circle to the graphics path.
path.AddEllipse(50, 50, 25, 25);
// Exclude the circle from the region.
myRegion.Exclude(path);
// Retrieve a Graphics object from the form.
Graphics formGraphics = e.Graphics;
// Fill the region in blue.
formGraphics.FillRegion(Brushes.Blue, myRegion);
// Dispose of the path and region objects.
path.Dispose();
myRegion.Dispose();
}
Private Sub FillRegionExcludingPath(ByVal e As PaintEventArgs)
' Create the region using a rectangle.
Dim myRegion As New Region(New Rectangle(20, 20, 100, 100))
' Create the GraphicsPath.
Dim path As New System.Drawing.Drawing2D.GraphicsPath
' Add a circle to the graphics path.
path.AddEllipse(50, 50, 25, 25)
' Exclude the circle from the region.
myRegion.Exclude(path)
' Retrieve a Graphics object from the form.
Dim formGraphics As Graphics = e.Graphics
' Fill the region in blue.
formGraphics.FillRegion(Brushes.Blue, myRegion)
' Dispose of the path and region objects.
path.Dispose()
myRegion.Dispose()
End Sub
설명
호출 Dispose 을 사용하면 다른 용도로 이 Region 항목에서 사용하는 리소스를 다시 할당할 수 있습니다.
사용을 마쳤으면 호출 Dispose 합니다 Region. 메서드는 Dispose 사용할 수 없는 상태로 둡니다 Region . 호출Dispose한 후에는 가비지 수집기가 차지하고 있던 메모리 Region 를 회수할 Region 수 있도록 모든 참조를 해제해야 합니다. 자세한 내용은 관리되지 않는 리소스 정리 및 Dispose 메서드 구현을 참조하세요.
메모
에 대한 마지막 참조를 해제하기 전에 항상 호출 Dispose 합니다 Region. 그렇지 않으면 가비지 수집기가 개체의 Region 메서드를 호출할 때까지 사용 중인 리소스가 Finalize 해제되지 않습니다.