Disposing objects

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, im have a trouble with the memory, my app is to big and it consumes a LOT of memory, i read the posts of dispose in the forum, and all recomends to leave the GC do this work for managed resources, should i dispose the datasets and other graphic objects in my app?

Thanks a lot
 
If some class implements IDisposable, or has Dispose() or Close(), most
probably this class holds some unmanaged resources and it is recommended
to call Dispose or Close once you are done with it. But I see no reason
to use Dataset.Clear().

Sunny
 
Hi Sunny, and what about the dataset.dispose

Sunny said:
If some class implements IDisposable, or has Dispose() or Close(), most
probably this class holds some unmanaged resources and it is recommended
to call Dispose or Close once you are done with it. But I see no reason
to use Dataset.Clear().

Sunny
 
Using Dispose() is a good practice, as it marks the objects for GC. It will
not automagically clear up memory, but it will help with cleaning up objects
when the GC fires. If you see a Dispose() method (ala the Connection
objects), use it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
JMArroyave said:
Hi, im have a trouble with the memory, my app is to big and it consumes a
LOT of memory, i read the posts of dispose in the forum, and all recomends
to leave the GC do this work for managed resources, should i dispose the
datasets and other graphic objects in my app?
 
Hi,

you'll be better off if you dispose everything what is IDisposable. And even
much better if you profile app for allocations, for example with
CLRProfiler, which you can get free from MS site.

You might have issues with memory even with code like this:

using (Brush b = new SolidBrush(Color.Black)) {
...some painting
}

If you call this is in loop or you have too many paints you will finish with
thousands of brushes in heap just because GC is not able to collect all
freed ones.

You might want to check also
http://msdn.microsoft.com/architecture/default.aspx?pull=/library/en-us/dnpag/html/scalenet.asp
for additional details on how to deal with GC. But profiler is your best bet
to find what is eating memory and why,

HTH
Alex

JMArroyave said:
Hi Sunny, and what about the dataset.dispose
consumes a LOT of memory, i read the posts of dispose in the forum, and all
recomends to leave the GC do this work for managed resources, should i
dispose the datasets and other graphic objects in my app?
 
Hi,

I do not know the internals of Dataset, so I can not tell you if it uses
some unmanaged resources. But in general, you use IDisposable pattern
when your class holds some unmanaged resources and you want to allow the
user to release them in timely manner.

In most cases, if IDisposable is implemented, it should be called (at
least with the buildin framework classes).

Sunny
 
DataSet has Dispose method. If object is IDisposable you must Dispose it
after use.

HTH
Alex

Sunny said:
Hi,

I do not know the internals of Dataset, so I can not tell you if it uses
some unmanaged resources. But in general, you use IDisposable pattern
when your class holds some unmanaged resources and you want to allow the
user to release them in timely manner.

In most cases, if IDisposable is implemented, it should be called (at
least with the buildin framework classes).

Sunny
consumes a LOT of memory, i read the posts of dispose in the forum, and all
recomends to leave the GC do this work for managed resources, should i
dispose the datasets and other graphic objects in my app?
 
Did I say something else?


DataSet has Dispose method. If object is IDisposable you must Dispose it
after use.

HTH
Alex


consumes a LOT of memory, i read the posts of dispose in the forum, and all
recomends to leave the GC do this work for managed resources, should i
dispose the datasets and other graphic objects in my app?
 
Back
Top