Which object should you dispose of?

You create an event receiver. The ItemAdded method for the event receiver contains the following
code segment. (Line numbers are included for reference only.) 01Dim recWeb As SPWeb =
properties.Web 02 Using siteCollection As New SPSite(“http://site1/hr”) 03 Using web As SPWeb
= siteCollection.OpenWeb() 04 Dim oWeb As PublishingWeb =
PublishingWeb.GetPublishingWeb(web) 05 Dim pubWebs As PublishingWebCollection =
oWeb.GetPublishingWebs() 06 For Each iWeb As PublishingWeb In pubWebs 07 Try 08 Dim
page As SPFile = web.GetFile(“/Pages/default.aspx”) 09 Dim wpManager As
SPLimitedWebPartManager = page.GetLimitedWebPartManager(PersonalizationScope.[Shared])
10 Finally 11 If iWeb IsNot Nothing Then 12 iWeb.Close() 13 End If 14 End Try 15 Next 16 End

Using 17 End Using You need to prevent the event receiver from causing memory leaks. Which
object should you dispose of?

You create an event receiver. The ItemAdded method for the event receiver contains the following
code segment. (Line numbers are included for reference only.) 01Dim recWeb As SPWeb =
properties.Web 02 Using siteCollection As New SPSite(“http://site1/hr”) 03 Using web As SPWeb
= siteCollection.OpenWeb() 04 Dim oWeb As PublishingWeb =
PublishingWeb.GetPublishingWeb(web) 05 Dim pubWebs As PublishingWebCollection =
oWeb.GetPublishingWebs() 06 For Each iWeb As PublishingWeb In pubWebs 07 Try 08 Dim
page As SPFile = web.GetFile(“/Pages/default.aspx”) 09 Dim wpManager As
SPLimitedWebPartManager = page.GetLimitedWebPartManager(PersonalizationScope.[Shared])
10 Finally 11 If iWeb IsNot Nothing Then 12 iWeb.Close() 13 End If 14 End Try 15 Next 16 End

Using 17 End Using You need to prevent the event receiver from causing memory leaks. Which
object should you dispose of?

A.
recWeb at line 01

B.
wpManager at line 09

C.
oWeb at line 04

D.
wpManager.Web at line 09



Leave a Reply 0

Your email address will not be published. Required fields are marked *