Using the WSS OM and Memory...

A while back I helped someone with an application that used the WSS Managed Object Model. It was using a massive amount of memory.

As it turned out it was due to using the WSS Object Model without calling the Dispose method on the SPWeb or SPSite classes. This caused hanging resources and were not being cleaned up properly, thus lots of memory used.

(Note: Unfortunately the WSS object model documentation does not mention that the SPWeb and SPSite objects implement the IDispose interface, or that it should be used to clean up resources after using them.)

By ensuring that the SPSite and SPWeb references were being Disposed it significantly reduced the amount of memory used ... thus less memory paging ... meaning less CPU usage. Overall a good result.

So, moral of the story ... make sure you are disposing your SPWeb and SPSite references (Note: this should not be done if you get the references via the GetContextSite method. see: KB 901259).

You can do this by manually calling the .Dispose() or .Close() method on the object or by using the using statement in C#.

E.g.

SPSite mySiteCollection = new SPSite(https://Server_Name);

// do stuff here ...

mySiteCollection.Dispose();

OR

using(SPSite mySiteCollection = new SPSite(https://Server_Name))

{

// do stuff here

}

The using statement/syntax can be used on objects that implement the IDispose interface.

I hope this helps anyone writing apps with the WSS Object model and experiencing memory usage problems.