I’ve wrote some piece of code which was used to clear security setting on item level in the library:

private void UsunDziedziczenieUprawnien_ExecuteCode(object sender, EventArgs e)
{
using (SPSite site = new SPSite (workflowProperties.SiteId))
{
using (SPWeb web = site.OpenWeb(workflowProperties.WebId))
{
workflowProperties.Item.BreakRoleInheritance(true );
SPGroup MyGroup = web.SiteGroups[“MyGroup” ];
workflowProperties.Item.RoleAssignments.Remove(MyGroup);
workflowProperties.Item.Update();
} } }

It looks simple, and nothing special. But each time this method has been lunched I get errors in SharePoint log files: “ERROR: request not found in the TrackedRequests. We might be creating and closing webs on different threads … “. And after that was entry:

An SPRequest object was not disposed before the end of this thread.  To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it.  This object will now be disposed.  Allocation Id: {35AEF0A1-C868-4205-9CCE-D557E252AFA8}  To determine where this object was allocated, create a registry key at HKEY_LOCAL_MACHINESOFTWAREMicrosoftShared ToolsWeb Server ExtensionsHeapSettings.  Then create a new DWORD named SPRequestStackTrace with the value 1 under this key.

What’s going on? Thanks to response of Wictor Wilén on at MDSN forums I found out that if your code contains BreakRoleInheritance you should use Dispose on ParentWeb . Well, I didn’t know that. And as you noticed this code use SPWeb and SPSite in way of best practices presented on MSDN – they were disposed. But not BreakRoleInheritance … Below code which is work fine for me

private void UsunDziedziczenieUprawnien_ExecuteCode(object sender, EventArgs e)
{

using (SPSite site = new SPSite(workflowProperties.SiteId))
{
using (SPWeb web = site.OpenWeb(workflowProperties.WebId))
{
SPList lista = workflowProperties.List;
SPListItem element = workflowProperties.Item;
SPGroup myGroup = web.SiteGroups[“MyGroup”];
try
{
element.BreakRoleInheritance(true);
element.RoleAssignments.Remove(myGroup);
element.Update();
}
finally
{
lista.ParentWeb.Dispose();

} }