Re: GC.Collect can be trusted?

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Christopher Ireland" <cireland@xxxxxxxxx> schrieb im Newsbeitrag
news:3B8B5DE7-7F87-4A76-AEFA-83089A363450@xxxxxxxxxxxxxxxx

"Because of the garbage collection package that is implemented in the
Microsoft .NET Framework, it is not possible to have a memory leak in
managed code. This suggests two questions: How then can a memory leak
occur? Why does it appear that you have a memory leak?"

Though garbage collection is very usefull to provent memory leaks, this
quote is a bit to optimistic. Sure ther can be memory leaks in managed code.
E.g. all static fields aren't collected. So any object directly or
indirectly referenced by a static field wouldn't be collected. Also any
variables very high in the call stack can prevent referenced object from
being collected, (though the lifetime of a variable can be shortened by the
compiler.)
By this a memory leak in managed code can easily construckted.

But it's very unlikely to happen in real code. And it's much 'harder' to do
it purposelessly in managed code, than in unmanaged colde.

Regards
Christof


.



Relevant Pages

  • Re: Memory Leak Experts!!!!
    ... I don't know the specifics of the memory leak conserning DataRows. ... Dispose as the article describes), but it could very well be the case ... >> managed code is solely handled by the framework, ...
    (microsoft.public.dotnet.framework.performance)
  • Re: GC.Collect can be trusted?
    ... E.g. all static fields aren't collected. ... By this a memory leak in managed code can easily construckted. ... Then should not remove those references to late or ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: GC performance - GC fragility
    ... code, but how to write according tools for managed code, without ... management) is just, well, a stinking memory hog. ... In a non-GC app a memory leak is a memory leak and an error that can be ...
    (borland.public.delphi.non-technical)
  • Re: Memory Leak in managed Code
    ... > That's something that I dont understand. ... It has nothing to do with your so called memory leak. ... > All my code is managed code and only use .NET libary (No third party ... framework you are running, so it would help us if you post your memory ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Possible bug in Bitmap.GetHicon()
    ... I am new to C# and the .NET Framework, and have not seen either of these commands before. ... >> I believe I found a bug in the Bitmap.GetHiconmethod that leads to a memory leak. ... >> When put in a loop, that continuously updates the Icon, even as slow as once a second, memory usage starts to climb and will eventually crash the program and cause strange behavior in Windows. ...
    (microsoft.public.dotnet.framework)