I have a feature receiver (scope=web) which creates subwebs below the web, where the feature is activated. This is used for application installation issues.
Is it necessary to dispose the created subwebs if they are returned from my createSubwebs(SPWeb web) method, which is called in the feature receiver?
Assuming you are creating the webs via
SPWebCollection.Addthe short answer is yes.SPWebobjects returned bySPWebCollection.Addalways have to be disposed.For more information see the Disposing Objects MSDN article.
Edit:
To clarify “returned for further use”. Let’s assume you have a utility class
WebCreatorwith a methodCreateWeb. This method creates a web and returns this web.We should not dispose the
SPWebobject in the methodCreateWebsince it will be used by the caller. However the caller is responsible to dispose the object.