"Resource hosting" and "unmanaged resources"-How to release LDB when creating MDB files

Source: Internet
Author: User

Recently I used ASP. NET to create an MDB file. After I found that the MDB file was created using ADOX. CATALOG, a temporary LDB log file will be generated;
The MDB file with LDB is in the "open" status, and it is difficult to perform operations such as "delete.
After searching for problems and summarizing methods on the Internet, we found that we still need to implement the IDISPOSABLE interface on the class to implement temporary hosting.

1. First, we will introduce "What are managed resources and unmanaged resources ":

(1) managed resources: Resources allocated and released by CLR management, typically managed memory, rather than allocated and released by the system; generally, you do not need to manually release the memory for a new object in the CLR or allocate an array. The memory occupied by the new object is the managed resource.

Unmanaged resources: All Window kernel objects (handles) are unmanaged resources, such as file handles, socket handles, form handles, fonts, brushes, and DC...

(2) supplement:
It should be said that the word "hosting" is and. net concept, we all know that the previous development tools, whether it is Delphi, VB compiled dll or exe files are binary files, can be directly recognized by the operating system. Microsoft has proposed to work hard with JAVA to achieve cross-platform purposes. net concept, the general principle is not to mention (there are books), simply put, is to propose a set of intermediate language (IL), and then let the program compile to generate intermediate language files, then translate and manage through our own CLR, so we can say that CLR is "hosted". Just kidding, no matter who cares about it. "Unmanaged" means the CLR cannot manage it.

2. The method for releasing the LDB file is as follows (create a class for implementation ):
'This class is used to generate MDB files
Public Class DisposeExample

Public Class Create_MDB
Implements IDisposable (after the IDISPOSABLE interface is declared, the following code is automatically generated)

Dim cat As ADOX. Catalog = New ADOX. Catalog

Private disposedValue As Boolean = false' checks redundant calls

Public Sub Create_MDB_Function (ByVal path As String)

Cat. Create (path)

End Sub

'Idisposable
Protected Overridable Sub Dispose (ByVal disposing As Boolean)
If Not Me. disposedValue Then
If disposing Then
'Todo: Release managed resources when explicitly calling

'Release the temporary LDB File
Cat = Nothing
System. GC. Collect ()

End If

'Todo: Release shared unmanaged Resources
End If
Me. disposedValue = True
End Sub
Finally, you only need to call this class where the function is implemented.

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.