문제

We have the following code:

    foreach (SPWeb website in collectionOfWebSites)
    {
           // Some code, no dispose of website

    }

SPDisposeChecker is reporting it as a memory leak. Should we dispose the website at the end of the foreach?

도움이 되었습니까?

해결책

Yes, dispose the SPWeb here each time!

다른 팁

Someone might need to back up me, but if you're getting an object from that collection, it does actually create an SPWeb instance each time (the collection is just a collection of object references rather than the objects themselves?), so you will indeed need to dispose of the object after each iteration.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top