# Make the extracted nodes a closed circle. $last->_link_to( $first ); return $first; } Note the destroy()routine. It
Monday, April 30th, 2007# Make the extracted nodes a closed circle. $last->_link_to( $first ); return $first; } Note the destroy()routine. It walks through all of the elements in a list and breaks their links. We use a manual destruction technique instead of the special routine DESTROY()(all uppercase) because of the subtleties of reference counting. DESTROY() runs when an object’s reference count falls to zero. But unfortunately, that will never happen spontaneously for doubleobjects because they always have two references pointing at them from their two neighbors, even if all the named variables that point to them go out of scope. If your code were to manually invoke the destroy()routine for one element on each of your doublelists just as you were finished with them, they would be freed up correctly. But that is a bother. What you can do instead is use a separate object for the header of each of your lists: package double_head; sub new { my $class = shift; my $info = shift; my $dummy = double->new; bless [ $dummy, $info ], $class; } The newmethod creates a double_headobject that refers to a dummy doubleelement (which is not considered to be a part of the list): sub DESTROY { my $self = shift; my $dummy = $self->[0]; $dummy->destroy; } The DESTROYmethod is automatically called when the double_headobject goes out of scope. Since the double_headobject has no looped references, this actually happens, and when it does, the entire list is freed with its destroy method:break Page 69 # Prepend to the dummy header to append to the list. sub append { my $self = shift; $self->[0]->prepend( shift ); return $self; } # Append to the dummy header to prepend to the list. sub prepend { my $self = shift;
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services