Re: Memory Leak Experts!!!!
From: Angelos Petropoulos (Angelos_Petropoulos_at_Yahoo.co.uk)
Date: 06/06/04
- Next message: Angelos Petropoulos: "Re: ThreadPool and IoCompletionPorts"
- Previous message: Angelos Petropoulos: "Re: Memory Leak Experts!!!!"
- In reply to: Mendonca: "Re: Memory Leak Experts!!!!"
- Next in thread: Mendonca: "Re: Memory Leak Experts!!!!"
- Reply: Mendonca: "Re: Memory Leak Experts!!!!"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 06 Jun 2004 13:01:35 +0100
Implementing the dispose design pattern (i.e. implementing the
IDisposable interface in .NET and calling .Dispose on your objects) is
a way of doing some cleaning up before the object is up for garbage
collection.
This means that you can clear your collections, close file streams,
etc. It does not however mean that by calling the .Dipose method you
are freeing up memory! This is all managed code, memory managed of
managed code is solely handled by the framework, not by the
programers.
Please have a read at the msdn article I posted in my other message.
For quick access I'll post it again:
Regards,
Angelos Petropoulos
On Sun, 6 Jun 2004 16:20:46 +1000, "Mendonca" <mendo@cso.com> wrote:
>I am wrapping a DataSet in my data structure, should i apply the IDisposable
>to my class and and call dataset.clear from there? Would that kill the
>tables inside the dataset? I have a look at reflector and it looks to be a
>good solution.
>
>thanks
>Mendoca
>
>"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
>news:u9$bso3SEHA.1768@TK2MSFTNGP10.phx.gbl...
>> >That's why you must dispose tables yourself -
>> what is your basis for this?
>>
>> --
>> Regards,
>> Alvin Bruney
>> [ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
>> Got tidbits? Get it here... http://tinyurl.com/27***
>> "AlexS" <salexru2000NO@SPAMsympaticoPLEASE.ca> wrote in message
>> news:uemDh$2SEHA.2944@tk2msftngp13.phx.gbl...
>> > Not sure if it was really interesting. But
>> >
>> > I've seen similar behavior with other apps, hence my conclusion. You
>just
>> > confirmed that. Once again - would be nice to try this on multiprocessor
>> > machine. On single processor one GC won't be able to cope properly with
>> > such
>> > number of created references.
>> >
>> > About working set and GC.Collect. Working set won't help in this case.
>GC
>> > might a bit, but not really. Collect might slow down things but not
>> > significantly, because collection is running with lesser priority than
>> > main
>> > process.
>> >
>> > If you really want to clean up things in real app, take it into profiler
>> > and
>> > experiment with explicit = null; assignments for references, which are
>not
>> > used anymore, and Dispose calls for internal objects. This test sample
>> > just
>> > is not worth the effort.
>> >
>> > As about DataSet.Dispose - it doesn't touch internal references, which
>are
>> > unknown to base class. That's why you must dispose tables yourself - use
>> > Clear method always and don't rely on simple Dispose call, because it is
>> > same base one as for DataSet. This might apply even to rows - you can
>> > check
>> > this yourself if you want to.
>> >
>> > I wonder if this "unclean" cleaning behavior will be corrected in next
>> > version of FW
>> >
>> > HTH
>> > Alex
>> >
>> > "Mendonca" <mendon@cso.com> wrote in message
>> > news:uY4t3H2SEHA.1768@TK2MSFTNGP10.phx.gbl...
>> >> Interesting you saying that my dispose doesnt touch tables and rows,
>> > because
>> >> i see much data from datarows surving the GC (realocated).
>> >> Doesnt the Dispose() method of a DataSet dispose of all underlying
>tables
>> >> and datarows?
>> >>
>> >> Cheers,
>> >> Mendonca
>> >>
>> >>
>> >> "AlexS" <salexru2000NO@SPAMsympaticoPLEASE.ca> wrote in message
>> >> news:uCXNZ0wSEHA.3660@tk2msftngp13.phx.gbl...
>> >> > Hi
>> >> >
>> >> > Quick look told me that you are creating around 300K new objects for
>> > every
>> >> > while loop execution. Most of the time it is tight loop - and most
>> >> important
>> >> > it seems, that your dispose doesn't touch tables, rows and dr[0]
>> >> reference.
>> >> >
>> >> > GC just can't keep pace with your production speed. Also because it
>has
>> > no
>> >> > time to run really. Did you try this on multiprocessor machine? I
>> >> > wonder
>> >> how
>> >> > it will behave there.
>> >> >
>> >> > HTH
>> >> > Alex
>> >> >
>> >> > "microsoft.news" <msuot@dmod.com> wrote in message
>> >> > news:uGXXuBtSEHA.3768@TK2MSFTNGP11.phx.gbl...
>> >> > > Anynone?
>> >> > >
>> >> > > "microsoft.news" <msuot@dmod.com> wrote in message news:...
>> >> > > > Hi all,
>> >> > > >
>> >> > > > Here is the example i would like everyone to concentrate on:
>> >> > > >
>> >> > > > static void Main(string[] args)
>> >> > > > {
>> >> > > > System.Collections.ArrayList list = new
>> >> System.Collections.ArrayList();
>> >> > > > System.TimeSpan tenMins =
>> >> > > >
>> >> > >
>> >> >
>> >>
>> >
>System.TimeSpan.FromTicks(DateTime.Now.Ticks).Add(System.TimeSpan.FromMinute
>> >> > > > s(1.5));
>> >> > > >
>> >> > > > while(System.TimeSpan.FromTicks(DateTime.Now.Ticks) < tenMins)
>> >> > > > {
>> >> > > > System.Data.DataSet ds;
>> >> > > > for(int lIndex = 0; lIndex < 100; lIndex++)
>> >> > > > {
>> >> > > > ds = new System.Data.DataSet();
>> >> > > > DataIt(ref ds);
>> >> > > > list.Add(ds);
>> >> > > > }
>> >> > > >
>> >> > > > for(int lIndex = 0; lIndex < 100; lIndex++)
>> >> > > > {
>> >> > > > ((System.Data.DataSet) list[lIndex]).Dispose();
>> >> > > > }
>> >> > > > list.Clear();
>> >> > > > }
>> >> > > > }
>> >> > > >
>> >> > > > static void DataIt(ref System.Data.DataSet ds)
>> >> > > > {
>> >> > > > System.Data.DataTable tb = new System.Data.DataTable("Table");
>> >> > > > tb.Columns.Add("data",typeof(Object));
>> >> > > >
>> >> > > > System.Data.DataRow dr = null;
>> >> > > > for(int lIndex = 0; lIndex < 1500; lIndex++)
>> >> > > > {
>> >> > > > dr = tb.NewRow();
>> >> > > > dr[0] = new object();
>> >> > > > tb.Rows.Add(dr);
>> >> > > > }
>> >> > > >
>> >> > > > ds.Tables.Add(tb);
>> >> > > > }
>> >> > > >
>> >> > > > So this app ran for approx 1.5 mins and I ran the CLRProfiler on
>> > this
>> >> > and
>> >> > > i
>> >> > > > got the following:
>> >> > > >
>> >> > > > Total allocation size: 90MB
>> >> > > > Total re-allocated: 41MB
>> >> > > >
>> >> > > > I can see that in this case if i ran the example for 10 mins i
>get
>> >> more
>> >> > > and
>> >> > > > more memory allocations. My question is simple, Shouldn't the GC
>> > clean
>> >> > up
>> >> > > > after the Dispose() method at all times? I can see a lot of
>garbage
>> >> from
>> >> > > the
>> >> > > > DataSet being promoted to gen1 and 2 and not being clean up at
>all.
>> >> > > > It looks like my datarows are never being cleaned up.
>> >> > > >
>> >> > > > Thanks in advance.
>> >> > > >
>> >> > > > Mendonca.
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > >
>> >> > >
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
- Next message: Angelos Petropoulos: "Re: ThreadPool and IoCompletionPorts"
- Previous message: Angelos Petropoulos: "Re: Memory Leak Experts!!!!"
- In reply to: Mendonca: "Re: Memory Leak Experts!!!!"
- Next in thread: Mendonca: "Re: Memory Leak Experts!!!!"
- Reply: Mendonca: "Re: Memory Leak Experts!!!!"
- Messages sorted by: [ date ] [ thread ]