I have created a Timer Job that iterates through a list of 100,000 items and finds the ones that are older than 120 days and "moves" them to a new site collection for archival. I am using a ContentIterator
and SPQuery
with a RowLimit
of 1000 to try to help with resources but the memory on the OWSTIMER.exe keep on increasing. After 1000 items processed it is using over 1GB in memory. I am using a using
statement on my source and destination SPSite
and SPWeb
but it does not appear to help.
My code looks somewhat like the following:
ContentIterator iterator = new ContentIterator();
SPQuery query = new SPQuery();
query.Query = completedItemsQuery;
query.RowLimit = 1000;
using (sourceSite = new SPSite(sourceUrl))
{
using (sourceWeb = sourceSite.OpenWeb())
{
sourceWeb.AllowUnsafeUpdates = true;
sourceList = sourceWeb.Lists["Example List"];
using (destinationSite = new SPSite(destinationUrl))
{
using (destinationWeb = destinationSite.OpenWeb())
{
iterator.ProcessListItems(sourceList, query, ProcessItem, ProcessError);
}
}
sourceWeb.AllowUnsafeUpdates = false;
}
}
My ProcessItem()
code simply iterates through each SPListItem
and its SPListItemVersion
to create the items on the destinationWeb but since these are non-disposable objects I cannot use any using
statements on them. I'm not sure if this is the issue?
Also, my SourceWeb
, DestinationWeb
, SourceSite
, and DestinationSite
are global variables. Could this be an issue?
Anyone have any ideas on this?