Languages have adopted several different methods for coping with object resurrection, most commonly by having two-phase garbage collection in the presence of finalizers, to prevent dangling references; and by only finalizing objects once, particularly by marking objects as having been finalized (via a flag), to ensure that objects can be destroyed. Java will not free the object until it has proven that the object is once again unreachable, but will not run the finalizer more than once. In Python, prior to Python 3.4, the standard
CPython implementation would treat resurrected objects identically to other objects (which had never been finalized), making indestructible objects possible. Further, it would not garbage collect cycles that contained an object with a finalizer, to avoid possible problems with object resurrection. Starting in Python 3.4, behavior is largely the same as Java: objects are only finalized once (being marked as "already finalized"), garbage collection of cycles is in two phases, with the second phase checking for resurrected objects.
Objective-C 2.0 will put resurrected objects into a "zombie" state, where they log all messages sent to them, but do nothing else. See also
Automatic Reference Counting: Zeroing Weak References for handling of
weak references. In the .NET Framework, notably C# and VB.NET, object finalization is determined by a finalization "queue", which is checked during object destruction. Objects with a finalizer are placed in this queue on creation, and dequeued when the finalizer is called, but can be manually dequeued (prior to finalization) with SuppressFinalize or re-enqueued with ReRegisterForFinalize. Thus by default objects with finalizers are finalized at most once, but this finalization can be suppressed, or objects can be finalized multiple times if they are resurrected (made accessible again) and then re-enqueued for finalization. Further,
weak references by default do not track resurrection, meaning a weak reference is not updated if an object is resurrected; these are called
short weak references, and weak references that track resurrection are called
long weak references. ==Applications==