[Python-Dev] The Trick

Samuele Pedroni pedronis at bluewin.ch
Sat Oct 18 15:29:56 EDT 2003


At 14:43 18.10.2003 -0500, Michel Pelletier wrote:
> > I don't like the trick of avoiding the copy if
> > the refcount is one;
> > AFAIK it can't be done in Jython.
>
>It may be possible with the java.lang.ref
>package using a somewhat similar trick by (I
>imagine) holding a soft reference and examining
>the object's rechability to the collector.
>-Michel

no, if you put the last reference to an object
in a weak-ref and trigger a GC (which is btw
expensive), well you can discover that there was
just one reference but you have also lost the object.

Now if you have a tiny wrapper/contents organization
you can overcome this, playing the trick with
the wrapper and keeping the contents, OTOH
as I said, the explicit GC is expensive, likely more
than allocating and copying.

regards.




More information about the Python-Dev mailing list