hello brian brian live(brian brian 'lorettagoodbye brian herewhen brian is assigned stringwe lose the last reference to the life instance and so trigger its destructor method this worksand it may be useful for implementing some cleanup activitiessuch as terminating server connection howeverdestructors are not as commonly used in python as in some oop languagesfor number of reasons that the next section describes destructor usage notes the destructor method works as documentedbut it has some well-known caveats and few outright dark corners that make it somewhat rare to see in python codeneedfor one thingdestructors may not be as useful in python as they are in some other oop languages because python automatically reclaims all memory space held by an instance when the instance is reclaimeddestructors are not necessary for space management in the current cpython implementation of pythonyou also don' need to close file objects held by the instance in destructors because they are automatically closed when reclaimed as mentioned in thoughit' still sometimes best to run file close methods anyhowbecause this autoclose behavior may vary in alternative python implementations ( jythonpredictabilityfor anotheryou cannot always easily predict when an instance will be reclaimed in some casesthere may be lingering references to your objects in system tables that prevent destructors from running when your program expects them to be triggered python also does not guarantee that destructor methods will be called for objects that still exist when the interpreter exits exceptionsin fact__del__ can be tricky to use for even more subtle reasons exceptions raised within itfor examplesimply print warning message to sys stderr (the standard error streamrather than triggering an exception eventbecause of the unpredictable context under which it is run by the garbage collector --it' not always possible to know where such an exception should be delivered cyclesin additioncyclic ( circularreferences among objects may prevent garbage collection from happening when you expect it to an optional cycle detectorenabled by defaultcan automatically collect such objects eventuallybut only if they do not have __del__ methods since this is relatively obscurewe'll ignore further details heresee python' standard manualscoverage of both __del__ and the gc garbage collector module for more information because of these downsidesit' often better to code termination activities in an explicitly called method ( shutdownas described in the next part of the bookthe operator overloading