开发者

Release memory from loaded xml?

开发者 https://www.devze.com 2023-01-28 06:39 出处:网络
For example, if you load a xml and use it for whatever reason: XDocument doc = XDocument.Load(\"my.xml\");

For example, if you load a xml and use it for whatever reason:

XDocument doc = XDocument.Load("my.xml");

Now that you have finished using it and want to release any memory used by it, initally i tought that setting it t开发者_StackOverflow中文版o null would do the job but it does not, so what is the proper way to release the used memory if that is possible ?


You are doing the proper thing. Let the GC worry about when it collects as it will when there's pressure.


The proper way is to simple stop using doc. The garbage collector will clean up the memory the next time it's invoked and determines doc is no longer referenced by your code.

If doc is a local the JIT will determine the last point it's used and make it eligable for collection at that point. There is no need to null it out. Raymond Chen has an excellent blog article explaining how this works

  • http://blogs.msdn.com/b/oldnewthing/archive/2010/08/10/10048149.aspx
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号