PrepAway - Latest Free Exam Questions & Answers

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.)

01 SPWeb recWeb = properties.Web;
02 using (SPSite siteCollection = new SPSite(“http://site1/hr”))
03 {
04 using (SPWeb web = siteCollection.OpenWeb())
05 {
06 PublishingWeb oWeb = PublishingWeb.GetPublishingWeb(web);
07 PublishingWebCollection pubWebs = oWeb.GetPublishingWebs();
08 foreach (PublishingWeb iWeb in pubWebs)
09 {
10 try
11 {
12 SPFile page = web.GetFile(“/Pages/default.aspx”);
13 SPLimitedWebPartManager wpManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
14 }
15 finally
16 {
17 if (iWeb != null)
18 {
19 iWeb.Close();
20 }
21 }
22 }
23 }
24 }

You need to prevent the event receiver from causing memory leaks.

Which object should you dispose of?

PrepAway - Latest Free Exam Questions & Answers

A.
oWeb at line 06

B.
recWeb at line 01

C.
wpManager at line 13

D.
wpManager.Web at line 13

Explanation:
MNEMONIC RULE: “sneaky, sneaky wpManager.Web”

Gets the web that this Web Part Page is stored in.

SPLimitedWebPartManager.Web Property
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.splimitedwebpartmanager.web.aspx

4 Comments on “Which object should you dispose of?


Leave a Reply