473,395 Members | 1,462 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,395 software developers and data experts.

CommandBuilder.Dispose - should I use it?

Ed
I just learned how to use the Commandbuilder and have
researched it a little bit further and see that there is a
dispose property. Should this be used after invoking the
command builder or does vb.net cleanup after itself on its
own? If I don't use it would this lead to a memory leak?

TIA,
Ed
Nov 20 '05 #1
3 1704
This brings up a vast topic of "How memory handling works in .NET".

First of all - try not to use CommandBuilder, it's not the recommended
approach unless your application is aimed to be quick and dirty.

Secondly - Dispose is thanks to IDisposable, all expensive objects must
implement dispose. Calling dispose will immediately ask the object to clean
itself. The other option is Finalize - which is well equal to the destructor
with a difference that you donot know when it will be called. It is
eventually called by the garbage collector, but you don't know when that
will happen and you cannot determine that with any degree of certainity.

Therefore, if an object exposes a dispose - call it when ur done with it.

Will not calling it result in a memory leak? It could .. though restarting
ur app will fix that to some extent and call the finalizers on each of the
objects, but thats not good either.

- Sahil Malik
Independent Consultant
You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/

"Ed" <an*******@discussions.microsoft.com> wrote in message
news:1c*****************************@phx.gbl...
I just learned how to use the Commandbuilder and have
researched it a little bit further and see that there is a
dispose property. Should this be used after invoking the
command builder or does vb.net cleanup after itself on its
own? If I don't use it would this lead to a memory leak?

TIA,
Ed

Nov 20 '05 #2
Ed
Thanks for your reply. Someone suggested I could use the
commandbuilder for the InsertCommand of the dataAdapter
object. My issue is/was that I felt I was writing too
many line of code for sqlParameters for the InsertCommand.

sqlParm = sqlDa.Parameters(New SqlParameter("@fld0",
Nvarchar (50), "fld0")
....
sqlParm = sqlDA.Parameters(New SqlParameter("@fld40",...)
....

The commandBuilder looked/looks quite appealing instead of
writing a bunch of extra lines of code as above.

So I suppose it would be a good idea to call Dispose when
I am done inserting data.

Thanks,
Ed

-----Original Message-----
This brings up a vast topic of "How memory handling works in .NET".
First of all - try not to use CommandBuilder, it's not the recommendedapproach unless your application is aimed to be quick and dirty.
Secondly - Dispose is thanks to IDisposable, all expensive objects mustimplement dispose. Calling dispose will immediately ask the object to cleanitself. The other option is Finalize - which is well equal to the destructorwith a difference that you donot know when it will be called. It iseventually called by the garbage collector, but you don't know when thatwill happen and you cannot determine that with any degree of certainity.
Therefore, if an object exposes a dispose - call it when ur done with it.
Will not calling it result in a memory leak? It could .. though restartingur app will fix that to some extent and call the finalizers on each of theobjects, but thats not good either.

- Sahil Malik
Independent Consultant
You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/
"Ed" <an*******@discussions.microsoft.com> wrote in messagenews:1c*****************************@phx.gbl...
I just learned how to use the Commandbuilder and have
researched it a little bit further and see that there is a dispose property. Should this be used after invoking the command builder or does vb.net cleanup after itself on its own? If I don't use it would this lead to a memory leak?
TIA,
Ed

.

Nov 20 '05 #3
Hi Ed,

When your programs have no troubles why would you not use the
commandbuilder, it has bugs however there are more parts in dotNet which
have bugs, so should that mean you should not use them. (The most terrible
one with bugs is that nice control the combobox). Therefore you should test
every program again and again.

The dispose should be used when there are unmanaged resources.

There are texts to use it always when it is implemented as a method, because
there is nothing wrong to do that. That is for me the same sentence as that
it does nothing wrong to set every value to zero before you close your
program. A lot of dispose are in a classes because it comes from a derived
class as the component class. (By instance every label has it).

Really separatly adviced it is with:
When you implements unmanaged resources in your classes.
Bitmaps
Dialogforms
Connections with more than 100 connections on a network (instead of close,
the dispose is here removing the connection string and probably something
extra in that method what is not dispose, however used by the devellopers to
reset the connectionpool).

I hope this helps?

Cor
Nov 20 '05 #4

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

Similar topics

2
by: Joao Santa Barbara | last post by:
Hi all i have a table with an autonumber field with a based select , i want to get all the three others commands, my problem is, i have a ds and i want to insert a new row ( my database gives...
10
by: Joao Santa Barbara | last post by:
hi all i need to work with the commandbuilder and with a transaction object how can i do this ???? thks JSB please donīt tell me that i have to do this ex:
1
by: Jason Shohet | last post by:
What we've done so far in our web applications: 1. We have no datasets dragged-and-dropped in Visual Studio. They are all defined in the code, generated at runtime. 2. when a user updates or...
1
by: Marina | last post by:
The commands that are generated by the SqlCommandBuilder are not quite right. I am calling GetUpdateCommand and GetDeleteCommand, modifying the results, and assigning them to the UpdateCommand and...
9
by: whaletyr | last post by:
When I try to update an access database using the commandbuilder and updatecommand. I get the An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll ...
1
by: Jeremy | last post by:
When executing myda.update(myds,"cert"). I get the message "The field 'Cert.DateofInspection' cannot contain a Null value because the Required property for this field is set to True. Enter a...
1
by: gomathinayagam | last post by:
hai, am only beginer in c#... i am trying to connect database with webform. using a technique that the fields of the table and the controls in a form are named same...then i try get the controls...
1
codemama
by: codemama | last post by:
I have written db provider independent code using interfaces (IDbDataAdapter).. However in order to update a database from an XML file I need to use the Command Builder to generate the Insert and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.