exam questions

Exam 70-488 All Questions

View all questions & answers for the 70-488 exam

Exam 70-488 topic 1 question 9 discussion

Actual exam question from Microsoft's 70-488
Question #: 9
Topic #: 1
[All 70-488 Questions]

A company uses SharePoint for internal collaboration. SharePoint is deployed on a server farm with a single front-end server, a single application server, and a dedicated database server.
You review existing Web Parts that read from and write to SharePoint lists. You find the following code in one of the utility classes and notice memory leaks in the method.

You need to ensure that there are no memory leaks in the method.
What should you do?

  • A. Add a finally statement and include site.Dispose ().
  • B. Add site.Dispose() to the catch statement.
  • C. Add a finally statement and include siteCollection.Dispose ();
  • D. Add siteCollection.Dispose() to the catch statement.
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️
Need to manually dispose of the siteCollection instance. This can be done through a finally statement.
Note:
* Try and finally blocks or a using statement would be required to avoid potential leaks when you create a disposable object within a foreach block, as shown in the following code example.
SPWebApplication webApp = siteCollectionOuter.WebApplication;
SPSiteCollection siteCollections = webApp.Sites;
SPSite siteCollectionInner = null;
foreach (siteCollectionInner in siteCollections)
{
try //Should be first statement after foreach.
{
Console.WriteLine(siteCollectionInner.Url);
//Exception occurs here.
}
finally
{
if(siteCollectionInner != null)
siteCollectionInner.Dispose();
}
}
* Why Dispose?
Several of the Windows SharePoint Services objects, primarily the SPSite class and SPWeb class objects, are created as managed objects. However, these objects use unmanaged code and memory to perform the majority of their work. The managed part of the object is much smaller than the unmanaged part.
Because the smaller managed part does not put memory pressure on the garbage collector, the garbage collector does not release the object from memory in a timely manner. The object's use of a large amount of unmanaged memory can cause some of the unusual behaviors described earlier. Calling applications that work with IDisposable objects in Windows SharePoint Services must dispose of the objects when the applications finish using them. You should not rely on the garbage collector to release them from memory automatically.
Reference: Best Practices: Using Disposable Windows SharePoint Services Objects

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Currently there are no comments in this discussion, be the first to comment!
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago