<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.0.6249.1">
<TITLE>Products, Debug manager, and refcounts</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">Hello list,</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">I've done large amounts of googling on the subject, but I can't find any simple explanation of what the Debug Manager is actually telling me concerning refcounts. </FONT></P>
<P><FONT SIZE=2 FACE="Arial">It's clear from various sources that, if between REQUESTs one sees a significant jump for a particular type's refcount, there's clearly a problem. (Please feel free to correct me if this is an oversimplification.) What's not clear is what one should normally expect.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">I make use of some python modules from Zope, generally using the following pattern:</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">[python script]</FONT>
<BR><FONT SIZE=2 FACE="Arial">from Products.MyProduct import facademodule</FONT>
<BR><FONT SIZE=2 FACE="Arial">try:</FONT>
<BR><FONT SIZE=2 FACE="Arial"> result = facademodule.doSomething(inputParams)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> return result</FONT>
<BR><FONT SIZE=2 FACE="Arial">finally:</FONT>
<BR><FONT SIZE=2 FACE="Arial"> del facademodule</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">[facademodule.py]</FONT>
<BR><FONT SIZE=2 FACE="Arial">def doSomething(inputParams):</FONT>
<BR><FONT SIZE=2 FACE="Arial"> import coremodule</FONT>
<BR><FONT SIZE=2 FACE="Arial"> coreObject = coremodule.CoreClass() </FONT>
<BR><FONT SIZE=2 FACE="Arial"> try:</FONT>
<BR><FONT SIZE=2 FACE="Arial"> resultValue = coreObject.doSomething(inputParams)</FONT>
<BR><FONT SIZE=2 FACE="Arial"> returnValue = {'resultValue':resultValue}</FONT>
<BR><FONT SIZE=2 FACE="Arial"> del resultValue</FONT>
<BR><FONT SIZE=2 FACE="Arial"> return returnValue</FONT>
<BR><FONT SIZE=2 FACE="Arial"> finally:</FONT>
<BR><FONT SIZE=2 FACE="Arial"> del coreObject</FONT>
<BR><FONT SIZE=2 FACE="Arial"> del coremodule</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">In the above example, I'm making hyper-vigilant use of 'del' to avoid keeping unneccessary references around. The facademodule's job is simply to send back the results of operations using primitive builtin types (int, list, dictionary) - because a) I don't want my user interface dependent on the coreObjects' structure; b) coremodule should be reusable outside the Zope process; and c) I don't want obsolete object references floating around.</FONT></P>
<P><FONT SIZE=2 FACE="Arial">After all this, however, I go to the Debug Manager and see that with every REQUEST to a page which makes use of this pattern somewhere, the refcounts for all manner of coremodule's Classes involved in the facademodule's work appear to be incremented by 1. (ex. after a REQUEST using the above pattern I'll see the reference count for Products.MyProduct.coremodule.CoreClass go up by 1.)</FONT></P>
<P><FONT SIZE=2 FACE="Arial">So, is this normal and expected? Or is it more likely that circular references in my code are causing the instances to be left hanging around? Is there some other approach that's recommended for using my own objects (residing outside of ZODB) and not bloating RAM, however slowly this may happen?</FONT></P>
<P><FONT SIZE=2 FACE="Arial">Thanks for any clues,</FONT>
<BR><FONT SIZE=2 FACE="Arial">Jim</FONT>
</P>
<BR>
<BR>
<BR>
</BODY>
</HTML>