Search This Blog

Friday, January 25, 2008

Avoiding memory leak in custom SharePoint code

In SharePoint applications with large customizations using custom code if objects using umanaged resources are not disposed, it would lead to memory leaks. The w3p process memory would drain quickly as more requests keep coming over a period of time.
You could check this quickly by looking at Virtual Memory in task manager. Other way would be to look at Private Bytes and .Net Memory performance counters.
Check your code for few obvious ones:

a) using (SPWeb web = new SPWeb(.....) )
b) using (SPWeb web = site.openWeb() )
c) Similary disposing the SpSite objects

Some other one are:

a) using (SPWeb web = site.openWeb() )
{
SPWeb parentWeb = web.parentWeb;

}
and even the
rootWeb property



Hope this helps...

No comments: