473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DataTable dispose ?

Hi,

Looking at the MSDN documentation, DataTable derives from a class named
"MarshalByValueComponent" - which implements IDisposable.

And, as a better practice - it is good to call .Dispose() on any class
that implements IDisposable

But, to my surprise, MSDN documentation or any sample doesnt explicity
make a call to .Dispose() when using instances of either DataTable,
DataSet, DataColumn etc

Can someone explain ?

Thanks
Kalpesh

Nov 17 '05 #1
7 15836

"Kalpesh" <sh*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Hi,

Looking at the MSDN documentation, DataTable derives from a class named
"MarshalByValueComponent" - which implements IDisposable.

And, as a better practice - it is good to call .Dispose() on any class
that implements IDisposable
Yes. Note that components added through designer are disposed automatically.

But, to my surprise, MSDN documentation or any sample doesnt explicity
make a call to .Dispose() when using instances of either DataTable,
DataSet, DataColumn etc

Can someone explain ?


Those are just samples about certain feature(s). They are not supposed to be
written properly (error handlind, etc)

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
Nov 17 '05 #2
Miha,

Good to hear from an expert. I read your blog :)
So, if I am using DataTable etc in my code (not dropped using the
designer), I must dispose it

Right ?

Kalpesh

Nov 17 '05 #3

"Kalpesh" <sh*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Miha,

Good to hear from an expert. I read your blog :)
:-)
So, if I am using DataTable etc in my code (not dropped using the
designer), I must dispose it

Right ?


Sort of. IDisposable is a contract that mean call Dispose when done with the
instance and you are safe if you do.
However, some people might argue that Dispose does nothing on certain
classes such as DataTable which might even be true at the present time. Yet
the implementation of Dispose might change for such a class in the future -
imagine that Dispose actually does something important in .net 3 version of
DataTable and your program will have problems if it doesn't call it.

The bottom line is: if you want to be on the safe side always call Dispose
if class implements IDisposable.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
Nov 17 '05 #4
If you create one programmatically, it doesn't have to be disposed, unless
it is bound to some disposable objects.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"Kalpesh" <sh*********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Miha,

Good to hear from an expert. I read your blog :)
So, if I am using DataTable etc in my code (not dropped using the
designer), I must dispose it

Right ?

Kalpesh

Nov 17 '05 #5
Hi Kevin,

Good to hear from another expert :)
This is what I understand from your sentence

Assuming I have a class which implements IDisposable (& .Dispose()
ofcourse)
Now, If this class instance has a reference to DataTable & if I call
myclassinstace.Dispose()

will this result in DataTable getting disposed automatically without me
writing any explicit code ?
Is this what you want to say ? How does it work unless I write
myDataTable.Dispose() in myIntsance.Dispose() method explicitly ?

Thanks
Kalpesh

Nov 17 '05 #6
Hi Miha/Kevin

Can you explain what Kevin has to say ?

Kalpesh

Nov 17 '05 #7
Hi Miha/Kevin,

Can you explain what Kevin has to say & my questions as well ?

Thanks
Kalpesh

Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave Elliott | last post by:
After inserting a new data row to a DataTable that is bound to a datagrid, I am unable to change data in a row that is after the newly added row without getting bizarre results. I have added the...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
3
by: clyyy2002 | last post by:
At added two column and more column hereafter,I immediately click del button,the program is no problem. but if i first click the DataGrid columnHeader and then click the del button, i find when...
5
by: ypul | last post by:
the code below given is connection class ... now I want to use the connection in another class , by using the getConnection method. where should I call con.dispose() ? in connection class or...
3
by: Jon | last post by:
I'm learning about datatables. When using the example provided by MS in the ..NET Framework Class Library for DATATABLE (see below) I get an error on line 3 that says "Type expected". Is something...
0
by: Deepak C.G via .NET 247 | last post by:
I want to dispose the image object in my child form, unless I won't dispose this object i can't delete the image file in my folder. I get this error in MDIparent form "An unhandled exception...
44
by: Smokey Grindle | last post by:
I have a list box on my form, but I need to databind it to a data table that is a private member of the form's class... so I basically have Public Class MyForm priate m_MyTable as new datatable...
4
by: Frank Lund | last post by:
Should we call .Dispose() every chance we get... on every object that exposes .Dispose()... and every time we have such an object? For example, is it true that *every* time I create a DataTable...
7
by: Jordan S. | last post by:
How can get rid of a DataTable instance? Set it to null + call Dispose on it? Anything else? Is Dispose really necessary given that the DataTable doesn't hold any resources (AFAIKT)? Yes, I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.