473,320 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

gc.get_referrers trouble

Hi,

I'm in the process of debugging a mem-leaking app. A recent thread here on
c.l.py mentioned the use of the gc module, so I gave it a try.

However, using get_referrers() yields in literally thousands of objects for
even the tiniest example like this:

import gc
a = [1]
print gc.get_referrers(1)

Running that from bash gives me this:

# python /tmp/test.py | wc
23 7196 67165

Now I'm confused - how do I interpret the results of get_referrers()
correctly?

--
Regards,

Diez B. Roggisch
Jul 18 '05 #1
3 2345
On Tue, 07 Sep 2004 20:00:58 +0200, Diez B. Roggisch wrote:
Hi,

I'm in the process of debugging a mem-leaking app. A recent thread here on
c.l.py mentioned the use of the gc module, so I gave it a try.

However, using get_referrers() yields in literally thousands of objects for
even the tiniest example like this:

import gc
a = [1]
print gc.get_referrers(1)


For space reasons, small ints are re-used. You get thousands of referrers
to the number 1 because, well, there are!

Try this:

import gc
a = [4444444444444]
print gc.get_referrers(4444444444444)
and you'll get something much more reasonable:

[(None, 4444444444444L), [4444444444444L]]
Jul 18 '05 #2
[Diez B. Roggisch]
I'm in the process of debugging a mem-leaking app. A recent thread here on
c.l.py mentioned the use of the gc module, so I gave it a try.

However, using get_referrers() yields in literally thousands of objects for
even the tiniest example like this:

import gc
a = [1]
print gc.get_referrers(1)

Running that from bash gives me this:

# python /tmp/test.py | wc
23 7196 67165
That just shows the number of lines (etc) of output, not how many
objects refer to 1. len(gc.get_referrers(1)) would tell you how many
container objects refer to 1. Little integers happen to be shared in
CPython, so there are likely to be referrers you don't know about. I
expect there are several dozen objects total that refer to 1, but not
more than that. Pick a larger number to match your "intuition"
better:
len(gc.get_referrers(82938732)) 1

Now I'm confused - how do I interpret the results of get_referrers()
correctly?


Start by not printing it as a string <wink>. It's a list of container
objects. The string representation of any one of those objects can
arbitrarily large.

A better start would be to download one of the test.py scripts for
Zope, and use a debug build. There's a TrackRefs class defined in
test.py that displays deltas in object counts (by type) across calls
to its update() method. Typical is to use that to find out which
kinds of objects are growing at an unreasonable rate, then fiddle the
guts of the TrackRefs class (via calls to things like gc.get_referrers
-- depends on where the evidence leads you) to zero in on a cause.
Jul 18 '05 #3
Diez> import gc
Diez> a = [1]
Diez> print gc.get_referrers(1)

Diez> Running that from bash gives me this:

Diez> # python /tmp/test.py | wc
Diez> 23 7196 67165

Diez> Now I'm confused - how do I interpret the results of
Diez> get_referrers() correctly?

Try your test with an object that's not massively shared:

% python
Python 2.4a2 (#46, Aug 29 2004, 08:53:23)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
import>>> import gc
a = [1000]
print gc.get_referrers(1000)

[(1000, None)]

CPython maintains a list of small integers (range(-1, 100) I believe) that
are reused and shared.

Skip
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: James | last post by:
Hi I am having some trouble getting a asp page to load. Im a noob to the asp side. I have followed knowledege base Article 301305. I am running 2000 adv, IIS 5.0 I have the following...
4
by: Jacek Dziedzic | last post by:
Hi! First of all, I hope my problem is not too loosely tied to the "standard C++" that is the topic of this group. I have some code that exhibits a strange behaviour: on one computer, where I...
0
by: Paul C | last post by:
Hello, everybody. I am having trouble running some of the VS.NET samples, specifically the CarSelector web app, which is very simple. The symptom is that the web controls (drop down listboxes and...
0
by: Alexandre Jaquet | last post by:
Hi does anybody know how to solve my trouble, when I try to create a MS Office project I always got trouble. I can't create office project when I try to create one vs.net restart ... :s
1
by: Jim Bancroft | last post by:
Hi everyone, I'm running into a problem with my ASP.Net application. I've just created a new aspx page which uses some new components of mine that inherit from ServicedComponent and are...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
2
by: JLupear | last post by:
I am having trouble with my code again, I had prepared a question and the code to upload, however I am having trouble posting it, are there limits to the amount of lines you can post? I split it...
0
by: mrchatgroup | last post by:
news from http://www.mrchat.net/myblog/myblog/small-accidents-mean-big-trouble-for-supercollider.html Small Accidents Mean Big Trouble for Supercollider Image Scientists expect startup...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.