Pergunta

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?

Foi útil?

Solução

Yes, dispose the SPWeb here each time!

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top