SharePoint Dispose Checker Tool 이 릴리즈 되었습니다.

바로가기 : SharePoint Dispose Checker Tool

Dispose 검사 툴은 SPSiteSPWeb 과 같이 IDisposable 인터페이스를 구현하는 객체들이 정상적으로 릴리즈 되도록 코드가 작성 되었는지를 검사해 주는 툴입니다.

이러한 객체들은 managed object 로 생성되지만 자체적으로 작업을 하는 데에 대부분은 unmanaged 코드/메모리를 사용하게 됩니다.

이 객체들의 managed 되는 부분의 비율이 작기 때문에 가비지 콜렉터는 즉각적으로 객체를 릴리즈 하지 않게 되고 이에 따라 상대적으로 많은 비중을 차지하는 unmanaged 메모리가 제때에 릴리즈 되지 못하고 누적되면 문제가 생길 수 있습니다.

따라서 코드 상에서 가비지 콜렉터에 의존하지 않고 이들을 명시적으로 릴리즈 해주도록 가이드 하고 있는데 SPDisposeCheck 툴은 그것이 제대로 이루어졌는지를 체크해 주는 툴입니다.

MSDN - Best Practices: Using Disposable Windows SharePoint Services Objects 을 참고하시면, using 블록이나 try,catch,finally,Dispose 등을 활용하는 코딩 기법이 제시되어 있으므로 이러한 테크닉을 활용하시기를 권장 드립니다.

다음은 문제가 있는 코드와 SPDisposeCheck 를 통한 검사 결과입니다.

16 : static void SPSiteCollectionAddLeak()// 릴리즈가 제대로 되지 않는 예제 (from MSDN)

{

SPWebApplication webApp = (

SPSiteCollection siteCollections = webApp.Sites;

SPSite siteCollection = siteCollections.Add( ,,);

}

Notes: Constructor called for Microsoft.SharePoint.SPSite but not assigned. This type should be assigned and subsequently disposed More Information:

Notes: Disposable type not disposed: Microsoft.SharePoint.SPSite ***This may be a false positive depending on how the type was created or if it is disposed outside the current scope More Information: