B
Barry Anderberg
I'm using a tool by Sci-Tech called the .NET Memory Profiler.
We have a massive .NET/C# application here and it has been exhibiting
memory leak behavior for some time. Attempting to remedy the problems
I am employing the aforementioned software in trying to track down the
problems.
After an hour or so of program execution, a snapshot of the managed
heap shows 27,025 BinaryReader objects as having been garbage
collected but never having been disposed.
The .NET Memory Profiler shows that these objects are being allocated
by the constructor of __BinaryParser.
I used another tool called Reflector to look behind the scenes and
sure enough, BinaryReader has resources such as its stream that are
only closed in its Dispose method. The class does not have a
finalizer, nor do any of its parent classes.
Therefore, if BinaryReader.Dispose() is not called, its stream will
never be closed. Granted, the stream in question is passed into the
constructor upon instantiation so the caller can still close the
stream when the time comes, but this isn't how it should be done.
I've seen lots of other classes that aren't being properly disposed
of. The ManualResetEvent isn't disposed of but luckily it has a
finalizer that is called by the GC- of course this alone is bad
programming because it will take longer to free the memory back to the
managed heap since objects that have a finalizer method will require a
minimum of two passes by the GC.
Any comments on this? I'm really getting tired of having to go around
and make sure the .NET Framework isn't making my software bloat over
time.
We have a massive .NET/C# application here and it has been exhibiting
memory leak behavior for some time. Attempting to remedy the problems
I am employing the aforementioned software in trying to track down the
problems.
After an hour or so of program execution, a snapshot of the managed
heap shows 27,025 BinaryReader objects as having been garbage
collected but never having been disposed.
The .NET Memory Profiler shows that these objects are being allocated
by the constructor of __BinaryParser.
I used another tool called Reflector to look behind the scenes and
sure enough, BinaryReader has resources such as its stream that are
only closed in its Dispose method. The class does not have a
finalizer, nor do any of its parent classes.
Therefore, if BinaryReader.Dispose() is not called, its stream will
never be closed. Granted, the stream in question is passed into the
constructor upon instantiation so the caller can still close the
stream when the time comes, but this isn't how it should be done.
I've seen lots of other classes that aren't being properly disposed
of. The ManualResetEvent isn't disposed of but luckily it has a
finalizer that is called by the GC- of course this alone is bad
programming because it will take longer to free the memory back to the
managed heap since objects that have a finalizer method will require a
minimum of two passes by the GC.
Any comments on this? I'm really getting tired of having to go around
and make sure the .NET Framework isn't making my software bloat over
time.