Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework


Unit Initialization and Finalization



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə260/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   256   257   258   259   260   261   262   263   ...   294
DelphiLanguageGuide

Unit Initialization and Finalization
On the .NET platform, units that you depend on will be initialized prior to initializing your own unit. However, there
is no way to guarantee the order in which units are initialized. Nor is there a way to guarantee when they will be
initialized. Be aware of initialization code that depends on another unit's initialization side effects, such as the creation
of a file. Such a dependency cannot be made to work reliably on the .NET platform.
Unit finalization is subject to the same constraints and difficulties as the Finalize method of objects. Specifically, unit
finalization is asynchronous, and, there no way to determine when it will happen (or if it will happen, though under
most circumstances, it will).
Typical tasks performed in a unit finalization include freeing global objects, unregistering objects that are used by
other units, and freeing resources. Because .NET is a memory managed environment, the garbage collector will
free global objects even if the unit finalization section is not called. The units in an application domain are loaded
and unloaded together, so you do not need to worry about unregistering objects. All units that can possibly refer to
each other (even in different assemblies) are released at the same time. Since object references do not cross
application domains, there is no danger of something keeping a dangling reference to an object type or code that
has been unloaded from memory.
Freeing resources (such as file handles or window handles) is the most important consideration in unit finalization.
Because unit finalization sections are not guaranteed to be called, you may want to rewrite your code to handle this
issue using finalizers rather than relying on the unit finalization.
The main points to keep in mind for unit initialization and finalization on the .NET platform are:

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   256   257   258   259   260   261   262   263   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin