Professional Visual Basic 2010 and .neT 4 phần 3

Vì vậy, hoạt động như thế này có thể mất một thời gian dài. Để minh họa điều này, bạn sẽ lưu ý rằng mã nắm bắt thời gian bắt đầu trước khi làm concatenations, và sau đó trong báo cáo in sử dụng phương pháp để có được sự khác biệt. Sự khác biệt đó được trả về như là một | Memory Management I 223 Release methods on the object s IUnknown interface. However in this scenario object A continues to hold a reference to object B and vice versa so the internal cleanup logic of these components is not triggered. In addition problems can occur if the clients do not properly maintain the COM object s reference count. For example an object will never be deactivated if a client forgets to call Release when the object is no longer referenced. To avoid this the unmanaged environment may attempt to take care of updating the reference count for you but the object s reference count can be an invalid indicator of whether or not the object is still being used by the application. For example consider the references that objects A and B hold. The application can invalidate its references to A and B by setting the associated variables equal to Nothing. However even though objects A and B are no longer referenced by the application the Visual Basic runtime cannot ensure that the objects are deactivated because A and B still reference each other. Consider the following Visual Basic 6 code Class CCircularRef Reference to another object. Dim m_objRef As Object Public Sub Initialize objRef As Object Set m_objRef objRef End Sub Private Sub Class_Terminate Call MsgBox Terminating. Set m_objRef Nothing End Sub The CCircularRef class implements an Initialize method that accepts a reference to another object and saves it as a member variable. Notice that the class does not release any existing reference in the m_objRef variable before assigning a new value. The following code demonstrates how to use this CCircularRef class to create a circular reference Dim objA As New CCircularRef Dim objB As New CCircularRef Call objB Call objA Set objA Nothing Set objB Nothing After creating two instances objA and objB of CCircularRef both of which have a reference count of one the code then calls the Initialize method on each object by passing it

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.