Re: finalizers depend on Java import
Jeff Allen <[email protected]>
| Newsgroups | gmane.comp.lang.jython.devel |
|---|---|
| Message-ID | <[email protected]> |
It can't be assumed that garbage collection runs at any particular time: even the call to gc is only a suggestion. Many CPython tests assume objects are destroyed when they pass out of scope, but they have to be modified or skipped in Jython. Occasionally we really need GC to run, but it seems you have to go to extraordinary lengths. See: http://hg.python.org/jython/file/83cd10f1826d/Lib/test/test_weakref.py#l10 What you observe is odd, but it's not actually incorrect, is it? Jeff Allen On 18/08/2014 22:27, Stefan Richthofer wrote: > I did more experiments and created a unit test for this phenomenon. If > nobody can explain this behavior, I would consider it a memory leak > and file a bug. > Let me comprehend my observations: > An import between A = SomeClass() and A = None causes A to be kept > alive for some reason, if gc runs after that. > Interestingly it appears that another import after A = None releases > this alive-keeping (see test_clear_object_surround_java_import_2 in > the attached file), unless this subsequent import happens in another > method (test_clear_object_surround_java_import_3). > It seems to make no difference, whether the imports are Java or Python > imports. > I know this is probably of rare interest, since it is a really strange > scenario to perform imports at such places. However, I find this > behavior strange enough to indicate that something is not sufficiently > understood/something is not working cleanly. Since I am currently > fixing finalizer issues and don't want to overlook something, I would > prefer to understand this despite the maybe rare common interest. > Somehow the import process establishes a strong reference to A, > keeping it alive. I suspect it might be hard to find out how this > happens. So if someone more familiar with Jython's import process > could point me somewhere, this would be helpful. > Stefan > ------------------------------------------------------------------------------ _______________________________________________ Jython-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jython-dev