Object new, dispose, and connection open and close concepts

Source: Internet
Author: User

This articleArticleThe reason is that some Web friends have questions about using (http://www.blueshop.com.tw/board/show.asp? Subcde = brd20080703145519kxs & fumcde = fum20041006161839lrj)

I'm grateful to you for your attention.

What is new?

We often see that when someone uses an object

 
Dim oemp as objemployeeeemp = new objemployee

In addition, the new version cannot be used. So what is new?
New is a production line, but I believe many people have to ask, what is [production line]
This should mention the running process of the computer program. When a program runs on a computer, it will open a blank space for the program section in the memory, and then route the program into that blank space.
Then, when the program is running, it is to remember the communication between the memory and the CPU, computing, and operation, and to [dig into the memory, transfer the program to that blank space] This process is [Production Line experiences ].
So what will happen if there is no new one? The program region does not connect to the memory, so it cannot be used as an example.

A little more personalized

 
Dim oemp as objemployee 'declares that oemp is an object of the objemployee type (this time there is no soul) eemp = new objemployee 'to generate a line of personal experiences (this time the reincarnation, the ghost becomes an entity, and you can start your work)
What is dispose?

When an object is used up, it will not be used in the future. At this time, the object has completed his life (now after the completion of new). Therefore, he can perform the dispose operation, the soil, and so on.
In practice, however, when an object is dispose in a memory, the memory is not cleared, indicating that the space is no longer used, it is not clear until the GC worker clears it.
Therefore, if you run out, do not execute dispose... so I will wait for a long time until I have not done it (just like someone lying on the ground, it has been more than a certain period of time (a month ??) Can be used by other programs.

The above describes the relationship between new and dispose.

What is open

When you have an actual experience, you can start the operation.
But it is not true.
In terms of connecion

 
Using conn as new connetion (connstr) dim Dr as sqldatareader using cmd as new sqlcommand ("Select...", Conn) DR = cmmd. executereader end usingend using

The above program will be released, and he will tell you... there is no open connection. For example, if you have set up a connection, but the connection is not connected, it cannot be used. Therefore, when you use datareader or cmmd. executenonequery, you must inform him that he is in use.

If dataadapter is used, this group is more harmful than others... he will see if there is a car, and he will use it if there is a car. If there is no car, he will open the channel himself and then use it.

What is close...

close indicates the connection channel, and the connection channel is closed.
next, compare it with the following dispose:
close is only to disable the channel
dispose transaction is the notification production system... I have completed my tasks. You can use this notebook again... then, just click confirm.
do you know where the difference is ??

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.