The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
Dear Dinesh
Thank you for reaching out to the Q&A Forum.
Based on my research, creating multiple ClientContext objects is generally not a good approach because each instance performs its own authentication and connection setup. Additionally, ClientContext caches every object it retrieves, which can lead to a ballooning memory footprint over time. This creates a trade-off between performance and memory usage when working with large datasets through CSOM.
A better approach is to reuse a single ClientContext when performing normal workloads on the same site. This avoids repeated authentication overhead and allows CSOM to batch multiple operations efficiently in a single ExecuteQuery call. Reusing the context improves performance for typical operations where the total number of loaded objects remains moderate.
You can either:
- Use one context and sequentially load and process data in smaller chunks (disposing of objects or clearing references as you go), or
- Instantiate fresh ClientContext objects for separate large portions of data, thereby releasing memory between portions.
Please note that this is based on my research, and I recommend sharing this discussion on developer-focused platforms such as GitHub or Microsoft Tech Community for broader insights.
Hope this information is helpful to you!
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.