I have an app which is uploading contents of a zip file into a Document Library.
While analyzing memory performance I have noticed the following:
Let's say that somewhere in our code we want to retrieve list of all
List that are present on our site. Here is the code:
var lists = _context.Web.Lists; _context.Load(lists, n => n.Include(x => x.Title)); _context.ExecuteQuery();
In my app I have to do quite a bunch of calls (e.g. retrieving all already existing files that are already uploaded in the document library, etc...).
While analyzing memory usage I have noticed that these object references are not cleared from memory of the
ClientContext. This means that I can anytime afterwards in my application simply call the following line:
var AnotherListOfLists = _context.Web.Lists;
and I no longer need to make a call towards
_context.ExecuteQuery() as all
Web.Lists have already been pre-loaded earlier. Thorough the lifetime of my application I am only using single instance of
ClientContext which is bulking up on the references the app is constantly making.
My question would be:
- Should I regularly dispose my
ClientContextand re-create while running long processes (such as uploading more than 50,000 files)
- Or there is a way how to 'free up' memory in my
I am quite new in SharePoint development, therefore any help or suggestions would be more than appreciated.