Re: GC and dispose




"Petros Amiridis" <petros@xxxxxxxxxxx> wrote in message
news:OyV$mvOlGHA.1204@xxxxxxxxxxxxxxxxxxxxxxx
Phil Wilson wrote:

You example doesn't help because there's nothing in Foo that needs
disposing, and Dispose isn't related to GC as you seem to be assuming.

What if it does have something that needs disposing? An if Dispose
doesn't have anything to do with GC, could tell me briefly what are
good practices that can make your application consume less memory?

I've noticed that my application starts and consumes several times more
memory than equivalent native applications. The problem is that
whenever I open/close windows in my application, the memory that it
occupies grows more. I wait and nothing happens. Shouldn't GC release
the memory as long as an object is not referenced any more?


I think to some degree it's a waste of time trying to help GC do its job
better in the way it seems you're thinking, as it is a fairly indeterminate
mechanism in the first place. It is somewhat important in some cases to
help GC have less to do though, because it can become a performance issue.
For example, using lots of stringbuilders for what are really just simple
concatenations. But that really manifests itself as a performance issue
more than a memory one in my testing.

As somebody else said, the Dispose pattern is for making sure UNMANAGED
resources inside your classes get cleaned up. That is, making sure there
are no memory leaks in things that GC doesn't try to deal with. That's why
the statement "Dispose doesn't have anything to do with GC".

I have no idea what "several times more memory than equivalent native
applications" means. Equivalent how -Functionality? Code? That's such a
nebulous comparison I don't think I'd spend much time worrying about that
either.

Is there a specific problem you're having or specific reason you think you
may have a memory leak in the application?


.



Relevant Pages

  • Re: Using Objects from another class to decrease Mem Usage
    ... and then call Dispose *immediately* after you ... IDisposable has no effect on the memory usage if your resources are ... static void Main ... if the GC runs after DoSomething it will not touch the test ...
    (microsoft.public.dotnet.general)
  • Re: Close - No Dispose - Memory Leak?
    ... I expect that in many cases close vs dispose issues are a red herring. ... are usually not the reason for issues with memory or object (connection ... complete N tasks/second and if the load stays below that level it works ... asking other applications to release memory). ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Memory Leak Experts!!!!
    ... > However as soon as app is restored all this memory is swapped back. ... > DataSet Dispose for example doesn't touch tables and rows. ... > free references in due time. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: How much do you leave to VB.Net GARBAGE COLLECTION???
    ... The first time that is checked if it can be destructed is as you invoke the method dispose as that is a member of the object or a member of its parent class. ... Not fysical direct, as one of the goals is that the GC does its work as it is needed in a kind of batch, to get the highest real performance, which is of course not when there is/are more then enough memory and resources available. ... Setting something to nothing means that you set the reference of the object to nothing. ... Dim myObject as New Object ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Bitmap constructor throwing System.Exception
    ... > calling Dispose() repeatedly may actually cause more problems if the users ... the virtual nature of memory on the PPC ... > possibility that long lived objects may be eating up available resources. ... >> problem is caused by the lack of managed memory. ...
    (microsoft.public.dotnet.framework.compactframework)