﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Alex Simkin commented on Challenge: Stop the leaks</title><description>Oh, sorry, didn't read carefully enough. That's exactly what was asked.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment16</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment16</guid><pubDate>Fri, 29 Apr 2011 22:23:52 GMT</pubDate></item><item><title>Alex Simkin commented on Challenge: Stop the leaks</title><description>@Duarte
  
  
Could you please explain the solution. BufferPoolWithLeakDetection throws when system tries to garbage collect MemoryLeakException because buffer was already garbage collected. But if buffer was already garbage collected, where is the memory leak? No, it wasn't returned to the pool, but that's not what was asked.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment15</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment15</guid><pubDate>Fri, 29 Apr 2011 22:21:18 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Stop the leaks</title><description>Duarte,
  
Nice, and similar to how I decided to do this.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment14</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment14</guid><pubDate>Fri, 29 Apr 2011 17:41:52 GMT</pubDate></item><item><title>Duarte Nunes commented on Challenge: Stop the leaks</title><description>Here's the code: 
[https://gist.github.com/948237](https://gist.github.com/948237)</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment13</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment13</guid><pubDate>Fri, 29 Apr 2011 12:44:46 GMT</pubDate></item><item><title>Duarte Nunes commented on Challenge: Stop the leaks</title><description>Maybe you could have a ConditionalWeakTable&lt;byte[], T&gt;, where T is a type that defines a finalizer and has a StackTrace. If you throw an exception on the finalizer thread, the process dies. When a buffer is returned to the pool, you remove it from the table.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment12</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment12</guid><pubDate>Fri, 29 Apr 2011 11:51:49 GMT</pubDate></item><item><title>Nathan Evans commented on Challenge: Stop the leaks</title><description>In that case, I look forward to seeing the solution.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment11</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment11</guid><pubDate>Fri, 29 Apr 2011 10:32:01 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Stop the leaks</title><description>This means that you now have to track IBufferContext, rather than just byte[]
  
There are better ways to do this.
  
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment10</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment10</guid><pubDate>Fri, 29 Apr 2011 10:24:50 GMT</pubDate></item><item><title>Nathan Evans commented on Challenge: Stop the leaks</title><description>Something like this is what I had in mind:
  
  
[http://pastebin.com/ULNYap6u](http://pastebin.com/ULNYap6u)  
  
Obviously you'd use using {} blocks, where appropriate, when dealing with the IBufferContext's.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment9</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment9</guid><pubDate>Fri, 29 Apr 2011 10:20:05 GMT</pubDate></item><item><title>Linkgoron commented on Challenge: Stop the leaks</title><description>Paul if I remember correctly you'd still be tied to the GC.
  
  
According to the docs using a ConditionalWeakTable and maybe another list with the keys would be better.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment8</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment8</guid><pubDate>Fri, 29 Apr 2011 09:55:08 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Stop the leaks</title><description>Nathan,
  
Show me the code.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment7</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment7</guid><pubDate>Fri, 29 Apr 2011 09:51:48 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Stop the leaks</title><description>Paul,
  
That makes it a pretty complex system, and you are doing a lot that you probably shouldn't.
  
There is also the issue of concurrent updates of timer &amp; buffer takes/ returns. 
  
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment6</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment6</guid><pubDate>Fri, 29 Apr 2011 09:51:15 GMT</pubDate></item><item><title>Ayende Rahien commented on Challenge: Stop the leaks</title><description>Paul,
  
We are writing one right now.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment5</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment5</guid><pubDate>Fri, 29 Apr 2011 09:50:01 GMT</pubDate></item><item><title>Nathan Evans commented on Challenge: Stop the leaks</title><description>Forgot to say, the StackTrace can be captured in the constructor (wrapped in #IF DEBUG of course) and stored in a private field. Then when the finalizer is called, maybe use Environment.FailFast to print a nice message with that stack trace info.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment4</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment4</guid><pubDate>Fri, 29 Apr 2011 09:49:49 GMT</pubDate></item><item><title>Nathan Evans commented on Challenge: Stop the leaks</title><description>Standard IDisposable pattern (with finalizer hook) and some #IF DEBUG conditional blocks.
  
  
The only uncertainty would be relying upon a GC to occur in order for the finalizer to be run. But your tests can simulate that.
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment3</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment3</guid><pubDate>Fri, 29 Apr 2011 09:41:24 GMT</pubDate></item><item><title>Paul Stovell commented on Challenge: Stop the leaks</title><description>That was a List&lt;Tuple&lt;WeakReference, StackTrace&gt;&gt; - you need a better blog engine :)
</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment2</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment2</guid><pubDate>Fri, 29 Apr 2011 09:39:42 GMT</pubDate></item><item><title>Paul Stovell commented on Challenge: Stop the leaks</title><description>Inside your implementation, have a List
&lt;tuple&lt;weakreference,&gt;
&gt;. In TakeBuffer, wrap the list you return in a weak reference, and store the stack trace. In ReturnBuffer, remove it from the list. Have a timer (or another trigger) and periodically go through the list. If any of the WeakReferences have a null target, the buffer has been leaked.
&gt;</description><link>http://ayende.com/4826/challenge-stop-the-leaks#comment1</link><guid>http://ayende.com/4826/challenge-stop-the-leaks#comment1</guid><pubDate>Fri, 29 Apr 2011 09:38:38 GMT</pubDate></item></channel></rss>