I have reviewed your changes and most of them won't make much difference and even unnecessary. Perhaps the leak comes from assumptions that JsonConvert.Import is supposed to dispose your streams? The general policy used in Jayrock is that it disposes streams it owns or opens unless it passes the ownership to user code. Here would be the right way to use JsonConvert.Import, where user code opens and disposes the reader:
object obj;
using (var reader = File.OpenText("data.json"))
obj = JsonConvert.Import(reader);
Process(obj);
- Atif
I'm build a server app that collects data from a number of devices with JSON (making around 1000 async requests per 30 seconds). It seems that there's momery leakage. So far I have found out that not all of it comes from jayrock, but there are a lot of undisposed stream objects. I had to make a number of changes (mainly adding using blocks around streamreader objects). I am attaching the edited file.