728x90
반응형
728x170
▶ Container.cs
namespace TestProject
{
/// <summary>
/// 컨테이너
/// </summary>
public class Container
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Public
#region Field
/// <summary>
/// 데이터
/// </summary>
public string Data;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - Container(data)
/// <summary>
/// 생성자
/// </summary>
/// <param name="data">데이터</param>
public Container(string data)
{
Data = data;
}
#endregion
}
}
728x90
▶ MainForm.cs
using System;
using System.Windows.Forms;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 전화 컨테이너
/// </summary>
private Container phoneContainer;
/// <summary>
/// 노트북 컨테이너
/// </summary>
private Container notebookContainer;
/// <summary>
/// 컨테이너 1
/// </summary>
private Container container1;
/// <summary>
/// 컨테이너 2
/// </summary>
private WeakReference container2;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.phoneContainer = new Container("Phone" );
this.notebookContainer = new Container("NoteBook");
this.container1 = this.phoneContainer;
this.container2 = new WeakReference(this.notebookContainer);
this.containerValueLabel1.Text = this.container1 == null ? "null" : this.container1.Data;
this.containerValueLabel2.Text = this.container2.Target == null ? "null" : (this.container2.Target as Container).Data;
this.collectButton.Click += collectButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region GC 수집 버튼 클릭시 처리하기 - collectButton_Click(sender, e)
/// <summary>
/// GC 수집 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void collectButton_Click(object sender, EventArgs e)
{
this.phoneContainer = null;
this.notebookContainer = null;
GC.Collect(0, GCCollectionMode.Forced);
GC.WaitForFullGCComplete();
this.containerValueLabel1.Text = this.container1 == null ? "null" : this.container1.Data;
this.containerValueLabel2.Text = this.container2.Target == null ? "null" : (this.container2.Target as Container).Data;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 극 좌표(Polar Coordinates) 사용하기 (0) | 2021.02.14 |
---|---|
[C#/COMMON] 3자 컴포넌트 어셈블리 서명하기 (0) | 2021.02.08 |
[C#/COMMON] 반복자(Iterator)를 사용해 텍스트 파일 반대로 읽기 (0) | 2021.02.08 |
[C#/COMMON] 모니터 수 구하기 (0) | 2021.02.08 |
[C#/COMMON] Enum 클래스 : GetValues 정적 메소드를 사용해 열거형 값 배열 구하기 (0) | 2021.02.07 |
[C#/COMMON] 모니터 정보 구하기 (0) | 2021.02.06 |
[C#/COMMON] 모니터 정보 구하기 (0) | 2021.02.06 |
[C#/COMMON] Version 클래스 : 버전 비교하기 (0) | 2021.02.04 |
[C#/COMMON] MSI 파일 설치시 관리자 권한 상승하기 (0) | 2021.02.03 |
[C#/COMMON] 커서 표시하기/숨기기 (0) | 2021.02.02 |
댓글을 달아 주세요