C#에서의 string.empty 문법은 다음과 같다.

public static readonly string Empty

 

msdn (http://msdn.microsoft.com/en-us/library/vstudio/system.string.empty.aspx) 을 보니 단순히 zero-length string인것 같다. "" 로 할당하는 것과 같다. 보통 string을 empty string으로 초기화할 때 많이 사용한다. 추가로 string이 empty 이거나 null인경우를 확인하기 위해서는 IsNullOrEmpty 메소드를 사용하면 된다.

 

하지만 내가 진짜 궁금했던 것은 c#에서 string.empty 로 초기화 하면 가비지 콜랙션의 수집대상이 되는가 였는데 정확한 문서를 찾지 못하였다.

 

반면에 Java에서는 아래와 같이 초기화하면 힙 메모리 영역에 배치되며 가비지 컬랙션의 수집대상이 되지만,

String s = new String();

 

 

아래와 같이 하면 가비지 콜랙터가 수집하지 않는다.

String s = "" ;

 

 

아래 더 자세한 링크가 있으니 시간될 때 확인해보자.

http://stackoverflow.com/questions/11700320/is-string-literal-pool-a-collection-of-references-to-the-string-object-or-a-co

+ Recent posts