TAILIEUCHUNG - Apress Introducing Dot Net 4 With Visual Studio_7

Tham khảo tài liệu 'apress introducing dot net 4 with visual studio_7', công nghệ thông tin, hệ điều hành phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | CHAPTER 13 IN SEARCH OF C CANONICAL FORMS Now can you think of what happens if the client of your object forgets to call Dispose or doesn t use a using statement Clearly there is the chance that you will leak the resource. And that s why the Win32Heap example type needs to also implement a finalizer as I describe in the next section. Note In the previous examples I have not considered what would happen if multiple threads were to call Dispose concurrently. Although the situation seems diabolical you must plan for the worst if you re a developer of library code that unknown clients will consume. Does the Object Need a Finalizer A finalizer is a method that you can implement on your class and that is called prior to the GC cleaning up your unused object from the heap. Let s get one important concept clear up front Finalizers are not destructors nor should you view them as destructors. Destructors usually are associated with deterministic destruction of objects. Finalizers are associated with nondeterministic destruction of objects. Unfortunately much of the confusion between finalizers and destructors comes from the fact that the C language designers chose to map finalizers into the C destructor syntax which is identical to the C destructor syntax. In fact you ll find that it s impossible to overload explicitly in C . You overload it implicitly by using the destructor syntax that you re used to if you come from the C world. The only good thing that comes from C implementing finalizers this way is that you never have to worry about calling the base class finalizer from derived classes. The compiler does that for you. Most of the time when your object needs some sort of cleanup code for example an object that abstracts a file in the file system it needs to happen deterministically for example when manipulating unmanaged resources. In other words it needs to happen explicitly when the user is finished with the object and not when the GC finally gets .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.