By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,692 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

gc.DEBUG_LEAK and gc.garbage

P: n/a
Hi,

I am new with python, and I am having a look to program that leaks.
The first thing I have to do is to determine if what leaks it is the
python code of my company.

I have set the DEBUG_LEAK flag with the GC and in the program cycle
printed the length of the garbage list. Is this enough to determine if
there is a leak in the python code? (the value rises). I am not
totally sure (see below).

I played with other flags as DEBUG_SAVEALL, but I think they are not
useful for what I want.

Finally, in this group I have seen a reference to an article in which
they had the look to gc.garbage after calling explicitally to
gc.collect(). is this necessary?

Thanks, Cesar
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

Cesar> I have set the DEBUG_LEAK flag with the GC and in the program
Cesar> cycle printed the length of the garbage list. Is this enough to
Cesar> determine if there is a leak in the python code? (the value
Cesar> rises).

That suggests to me that you have objects with __del__ methods that are
involved in cycles. Get rid of the __del__ methods or figure out some way
to break the cycles.

Cesar> Finally, in this group I have seen a reference to an article in
Cesar> which they had the look to gc.garbage after calling explicitally
Cesar> to gc.collect(). is this necessary?

Generally, no, but if you want to make sure the collector has run when you
want to look at gc.garbage it's convenient to call gc.collect() first.

Skip
Jul 19 '05 #2

P: n/a
Cesar wrote:
I have set the DEBUG_LEAK flag with the GC and in the program cycle
printed the length of the garbage list. Is this enough to determine if
there is a leak in the python code? (the value rises).
Well, define "a leak". It could mean a number of things:

- an object that is not used anymore, but still referenced
from a "live" object.
This will not be released until the reference from the live
object is broken.
- an object that is not referenced "from the outside", but
still referenced from a cycle. It will not be released immediately,
but will be released eventually when the cyclic GC runs.
- an object that is part of a cycle, but not even released by
the cyclic GC.
- an object that is never released because its reference counter
is wrong.

Except for the last category, none of these are "true" leaks,
since you could always arrange to release them eventually through
explicit Python code.
I played with other flags as DEBUG_SAVEALL, but I think they are not
useful for what I want.
DEBUG_LEAK includes DEBUG_SAVEALL; all objects in cycles are not
released, but added to gc.garbage. This is to detect whether
you have objects that are not released even when they become
unreachable, but only when the GC runs. Some people consider
this a leak, and DEBUG_LEAK helps you to find such objects
(so you can break the cycles explicitly).

If you want to know whether you have objects that participate
in cycles and are not released by the cyclic GC, then don't
set any flags, and just look at gc.garbage.
Finally, in this group I have seen a reference to an article in which
they had the look to gc.garbage after calling explicitally to
gc.collect(). is this necessary?


Necessary to do what? If you want to verify that all unreferenced
objects are collectable, you should check gc.garbage after invoking
gc.collect().

Regards,
Martin
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.