Is there a way to get the number of currently open SPRequests in code?
Being able to see the count of SPRequests would b开发者_如何学编程e pretty useful for debugging, so - is there a way?
Excellent question, it's really annoying to see these warnings in the ULS logs (C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\LOGS)
The SPRequest warning is usually related to undisposed SPWeb or SPSite objects, the best way to avoid this is by doing
using(SPWeb or SPSite instance)
{
//some code
}
The using statement takes care of disposing the objects properly.
There are some tools available to help you out, e.g. SPDisposeCheck
More info on this on http://msdn.microsoft.com/en-us/library/aa973248.aspx
I would say your best bet for looking at that would be to use a memory profiling tool. Not only should you be able to see the count, but depending on the tool you can see a stack trace of where objects were allocated.
Theres a few out there, for example check out this post
.NET Memory Profiling Tools
精彩评论