This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
gdb.Value instances created from python aren't released until the next command
- From: Johan Erlandsson <jeoerl at gmail dot com>
- To: gdb at sourceware dot org
- Date: Wed, 10 Nov 2010 11:27:29 +0100
- Subject: gdb.Value instances created from python aren't released until the next command
Hi
I have seen a problem with memory consumption when using python
scripts. In my case I work against a core dump and analys heap data
(performance is good and we can analys a lot of data).
I have made a small example that I belive demonstrates the same problem:
<BEGIN ex_cmd.py>
import gdb
import gc
class T1Command (gdb.Command):
def __init__ (self):
super (T1Command, self).__init__ ("t1", gdb.COMMAND_DATA,
gdb.COMPLETE_NONE)
def invoke (self, arg, from_tty):
# change sym to any available structure
val = gdb.parse_and_eval("sym")
for i in range(6000000):
# change f to any field in structure
val["f"]
gc.collect()
class T2Command (gdb.Command):
def __init__ (self):
super (T2Command, self).__init__ ("t2", gdb.COMMAND_DATA,
gdb.COMPLETE_NONE)
def invoke (self, arg, from_tty):
print "t2"
T1Command()
T2Command()
<END ex_cmd.py>
Here are two commands, running the command "t1" will consume a lot of
memory. Running the command "t2" will release memory created while
running "t1".
(gdb) python execfile('/path/ex_cmd.py')
(gdb) t1
(gdb) t2
As I see it there shouldn't be any reason for it to consume memory as
long as the Python instances are released.
>From my own investigation it seems that it is 'struct value' that is
not released until the next command is run. While running the command
I can see that this funtion in 'gdb/python/py-value.c' is called:
/* Called by the Python interpreter when deallocating a value object. */
static void
valpy_dealloc (PyObject *obj)
but reference count is 2 when called so we wont release it.
When you start a new command, the 'struct value' are released when
calling this function in 'gdb/value.c':
/* Free all the values that have been allocated (except for those released).
Call after each command, successful or not.
In practice this is called before each command, which is sufficient. */
void
free_all_values (void)
Also I see the same pattern for non-python commands. Is this how it is
intended to work? Can you see any other way how to make it work?
Regards
Johan