user3164883
user3164883

Reputation: 91

Memory leak in JSON serialization

I have created a C# application and I have used JSON serialization. Currently the app is consuming too much working set memory. Could it be because of the NewtonSoft JSON library I have used? I also have used BouncyCastle library. Can it also create memory leaks? Please advice.

Upvotes: 1

Views: 4706

Answers (2)

charlielam
charlielam

Reputation: 11

Have you tried DataContractJsonSerializer or JavaScriptSerializer instead of JSON.net? they are build-in in C# and MAY cause less problem than external libraries.

Details: DataContractJsonSerializer

JavaScriptSerializer

Upvotes: 1

Aron
Aron

Reputation: 15772

I would suggest you try out Ants Memory Profiler. Memory management makes it difficult generally to locate memory usage.

However from my experience, Newtonsoft.Json doesn't have much in the way of potental memory leaks.

I haven't used BouncyCastle myself, so I can't tell you how well it works with memory. Given the nature of crypto, I would expect there are some parts that are unmanaged/native. Ensure that all IDisposable are Disposed on ALL code paths (I suggest using using, to ensure that happens even in the exceptional cases).

However, generally speaking, I would point the finger at my own code before well used community created libraries.

Upvotes: 0

Related Questions