This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bgilbert
Recipients bgilbert
Date 2011-08-24.21:53:54
SpamBayes Score 9.57198e-05
Marked as misclassified No
Message-id <1314222835.27.0.518600149254.issue12836@psf.upfronthosting.co.za>
In-reply-to
Content
Section 15.17.1.15 of the ctypes documentation illustrates the use of cast() thusly:

>>> a = (c_byte * 4)()
>>> cast(a, POINTER(c_int))
<ctypes.LP_c_long object at ...>
>>>

Executing the cast() causes a._objects to gain a reference back to a:

>>> a = (c_byte * 4)()
>>> a._objects
>>> cast(a, POINTER(c_int))
<__main__.LP_c_int object at 0x7fb879065b90>
>>> a._objects
{140430281170384: <__main__.c_byte_Array_4 object at 0x7fb879065dd0>}
>>> a
<__main__.c_byte_Array_4 object at 0x7fb879065dd0>
>>> 

If large temporary arrays are allocated, cast, used, and discarded in a tight inner loop, a lot of memory can thus be consumed by self-referencing objects before the garbage collector has a chance to run.  Even if this behavior is correct from the perspective of ctypes, it is surprising.
History
Date User Action Args
2011-08-24 21:53:55bgilbertsetrecipients: + bgilbert
2011-08-24 21:53:55bgilbertsetmessageid: <1314222835.27.0.518600149254.issue12836@psf.upfronthosting.co.za>
2011-08-24 21:53:54bgilbertlinkissue12836 messages
2011-08-24 21:53:54bgilbertcreate