CSC510234. Avoid having Static SP-object as field inside classes

Avoid having SPite, SPWeb, SPList, SPFile, SPFolder, SPListItem as static field inside classes.

Description

First of all, having a SPSite, SPWeb objects as static fields may cause a memory leak. You should open them as late as possible and dispose them as early as possible.

Second, about SPList, SPFile, SPFolder and SPListItem. All of these objects have link to owner web object, direct or through one related object - it is SPWeb object on which they were created. When the owner web is disposed, the SPList and SPListItem objects created from that web, cannot be used any longer.

Resolution

Pass SP - Objects objects as a methods parameters most of the time.

Links

No links are provided.

Last edited Jan 17, 2014 at 6:38 AM by dvd73, version 3

Comments

No comments yet.