[issue25512] apparent memory leak using ctypes

2015-10-30 Thread Martin Smith

Martin Smith added the comment:

I'm persuaded that this is not a sustained memory leak.

Thanks to Martin Panter and Benjamin Peterson for the tests and the careful 
explanations.

Apologies for distracting busy people.

--
resolution:  -> not a bug
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25512] apparent memory leak using ctypes

2015-10-30 Thread Benjamin Peterson

Benjamin Peterson added the comment:

cast() always creates a ref cycle, which is probably what you are seeing.

>>> from ctypes import c_double, cast, POINTER
>>> samples = (c_double*23)()
>>> cast(samples, POINTER(c_double))
<__main__.LP_c_double object at 0x7f33bc920560>
>>> samples._objects
{13986018358: <__main__.c_double_Array_23 object at 0x7f33bc8ef280>}
>>> samples
<__main__.c_double_Array_23 object at 0x7f33bc8ef280>

--
nosy: +benjamin.peterson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25512] apparent memory leak using ctypes

2015-10-29 Thread Martin Panter

Martin Panter added the comment:

I am running your script with the Python 3.5.0 from Arch Linux on an x86-64 
computer. The reported numbers slowly increase and then plateau at 221 million:

$ python ctype_stressor.py
   1  0.000e+00  3.8010880e+07
  10  2.8538793e+00  1.4648934e+08
  20  2.9961207e+00  1.5189606e+08
  30  3.1383621e+00  1.5730278e+08
  40  3.2806034e+00  1.6270950e+08
  50  3.4512931e+00  1.6919757e+08
  60  3.5935345e+00  1.7460429e+08
  70  3.7357759e+00  1.8001101e+08
  80  3.8780172e+00  1.8541773e+08
  90  4.0202586e+00  1.9082445e+08
 100  4.1909483e+00  1.9731251e+08
 110  4.3331897e+00  2.0271923e+08
 120  4.4754310e+00  2.0812595e+08
 130  4.6176724e+00  2.1353267e+08
 140  4.7599138e+00  2.1893939e+08
 150  4.7883621e+00  2.2002074e+08
 160  4.7883621e+00  2.2002074e+08
. . .
 270  4.7883621e+00  2.2002074e+08
 280  4.8043103e+00  2.2062694e+08
. . .
 410  4.8043103e+00  2.2062694e+08
 420  4.8133621e+00  2.2097101e+08
. . .
1300  4.8133621e+00  2.2097101e+08

Monitoring the process with “htop”, I see the total virtual memory (VIRT) 
ramping up to about 79 MiB, and then jumping back to about 62 MiB, and the 
resident physical memory (RES) ramps within 36–53 MiB in a similar pattern.

Similarly, Python 2.7.10 ramps within RES = 32–43 MiB, and your script is 
showing 177 million:

1140  5.5962126e+00  1.7691443e+08

Is this the same as what you are seeing? How long do you have to you run your 
script for?

The memory figures in your script seem to be out by a factor of four, assuming 
the third column is meant to be a number of bytes. But I don’t think there is a 
memory leak. At worst there is an unexpected dependency cycle between objects, 
meaning the memory builds up a bit until the garbage collector runs.

--
nosy: +martin.panter
versions: +Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25512] apparent memory leak using ctypes

2015-10-29 Thread Martin Smith

New submission from Martin Smith:

Attached file demonstrates a memory leak arising in ctypes (I think).  Leak 
occurs in both 2.7 and 3.5, though at different rates.

Humble apologies if I've screwed up somewhere.  Very nervous about submitting 
this.

--
components: ctypes
files: ctype_stressor.py
messages: 253688
nosy: blindgoat
priority: normal
severity: normal
status: open
title: apparent memory leak using ctypes
type: resource usage
versions: Python 3.5
Added file: http://bugs.python.org/file40896/ctype_stressor.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com