[PYTHON MATRIX-SIG] Re: may be a bug
Tser-Yuan (Brian) Yang
tbyang@icf.llnl.gov
Fri, 28 Jun 1996 14:06:08 -0700 (PDT)
I finally figure out what is holding the two extra reference counts in the
following block of script.
>>> from Numeric import *
>>> a=array((1,2))
>>> import sys
>>> sys.getrefcount(a)
2
>>> print a
1 2
>>> sys.getrefcount(a)
4
One is the variable 'data' in arrayToString (in ArrayPrinter.py), and the
other is the exception handler. After I added 'del data' before the
return of arrayToString, and commented out some statements in arrayToString:
if max_line_width is None:
# try:
# max_line_width = sys.output_line_width
# except AttributeError:
max_line_width = 77
if precision is None:
# try:
# precision = sys.float_output_precision
# except AttributeError:
precision = 8
if suppress_small is None:
# try:
# suppress_small = sys.float_output_suppress_small
# except AttributeError:
suppress_small = 0
The same block of script gives:
>>> from Numeric import *
>>> a=array((1,2))
>>> import sys
>>> print a
1 2
>>> sys.getrefcount(a)
2
I agree this is probably a feature rather than a bug, since these reference
counts will be released after printing another array. Just to point this out
in case some of you may be interested.
Brian Yang
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================