سؤال

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