Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XmlSerializer Memory Leak - Created Inside Loop #329

Open
ghost opened this issue Dec 18, 2018 · 1 comment
Open

XmlSerializer Memory Leak - Created Inside Loop #329

ghost opened this issue Dec 18, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Dec 18, 2018

The class SObjectList function WriteXml(XmlWriter writer) creates a new XmlSerlializer inside a loop, which is very inefficient. Putting the serializer creation outside of the loop increases speed and decreases memory usage.

Each new XmlSerlializer is internally compiled and cached, so for long running applications* the memory usage will slowly rise over time as the cached serializers can never be garbage collected. To reuse a cached serializer you must use a constructor XmlSerializer(typeof(T)) but that means you will need to use an [XmlRoot("sObject")] attribute on your models (?). Or use your own caching strategy, see this link for details:

https://stackoverflow.com/questions/23897145/memory-leak-using-streamreader-and-xmlserializer

* We use Azure Functions to send bulk data to Salesforce on a schedule, which would slowly climb to >3GB private bytes used before crashing. Since making this change the private bytes used have flat-lined at ~200MB

@EricHirst-BZ
Copy link

It looks like #255 would fix this. You're right; the code in SObject will definitely result in a memory leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant