Python vs Java garbage collection?

Isaac To kkto at csis.hku.hk
Mon Dec 30 00:18:44 EST 2002


>>>>> "Stuart" == Stuart D Gathman <stuart at bmsi.com> writes:

    Stuart> Can you think of a way to register a function to get called when
    Stuart> the current block exits?  If so, then it is pretty
    Stuart> straightforward to implement the proposal in pure python.  The
    Stuart> auto function simply adds the object to a list, and the block
    Stuart> exit function calls the cleanup function for objects in the list
    Stuart> with all the appropriate try..finally wrappers.

Perhaps no need to do it in the block level.  After all, there is no
block-level variables in Python either.  (Even "[a+1 for a in [1]]" leaves a
local variable a in the function.)  It might be simpler if variable
management is done when function, class and file scope exits.

    Stuart> Actually, you would want to register a function for the calling
    Stuart> block, or perhaps an arbitrary stack frame.  It would also help
    Stuart> to be able to retrieve the current callable object for a frame
    Stuart> to make the system thread-safe.

No comment, since I don't quite understand this.

    Stuart> I can't see anyway around having to patch the interpreter to get
    Stuart> the hook in there.  And I think the compiler needs to be
    Stuart> involved to cleanup at block exit (instead of function exit).

Yes, any way to mimic that without modifying the language itself would lead
to ugly code.  So I ask about a PEP.

Regards,
Isaac.



More information about the Python-list mailing list