You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Matt Goodwin <mg...@metalexis.com> on 2005/07/05 23:48:53 UTC

[digester] Digester pinning objects in memory

I am using commons-digester for creating some objects from some xml 
files.  When I look at this with JProbe Digester (and some other 
internal stuff are still referencing the object that is parsed.  The 
code is as follows, any help would be greatly appreciated: 

Digester digester = initializeDigester();
CommissionStatement commissionStatement = 
(CommissionStatement)digester.parse(new 
StringReader(FileUtils.readFile(file.getAbsolutePath())));
digester.clear();
digester=null;
...snip
clearCommissionStatement(commissionStatement);

private Digester initializeDigester() {
    Digester digester = new Digester();
    digester.setValidating(false);
    
digester.addObjectCreate("CommissionStatementVO",CommissionStatement.class);
    
digester.addObjectCreate("CommissionStatementVO/AgentStatementVO",AgentStatement.class);
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/StatementDate","statementDate");
    
digester.addObjectCreate("CommissionStatementVO/AgentStatementVO/AgentInfoVO",AgentInfo.class);
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/FirstName","firstName");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/Name","lastName");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/AgentId","agentId");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/Address1","address1");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/Address2","address2");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/City","city");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/State","state");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/Zip","zip");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/AgentType","agentType");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentInfoVO/DisbursementSource","disbursementSource");
    
digester.addSetNex("CommissionStatementVO/AgentStatementVO/AgentInfoVO","setAgentInfo","com.equitrust.commissionloader.beans.AgentInfo");
    
digester.addObjectCreate("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO",AgentStatementDetail.class);
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/AgentNumber","agentNumber");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/ProductType","productType");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/FirstName","firstName");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/Name","lastName");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/EffectiveDate","effectiveDate");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/ProcessDate","processDate");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/OwnerName","ownerName");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/PolicyNumber","policyNumber");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/InitialPremium","initialPremium");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/CommissionRate","commissionRate");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/CommissionPremium","commissionPremium");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/Type","commissionType");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO/AmountDue","amountDue");
    
digester.addSetNext("CommissionStatementVO/AgentStatementVO/AgentStatementLineVO","addAgentStatementDetail","com.equitrust.commissionloader.beans.AgentStatementDetail");
    
digester.addObjectCreate("CommissionStatementVO/AgentStatementVO/AgentEarningsVO",AgentEarning.class);
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentEarningsVO/TaxableIncome","taxableIncome");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentEarningsVO/TaxableIncomeYTD","taxableIncomeYTD");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentEarningsVO/PositivePolicyEarnings","positiveEarnings");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentEarningsVO/NegativePolicyEarnings","negativeEarnings");
    
digester.addBeanPropertySetter("CommissionStatementVO/AgentStatementVO/AgentEarningsVO/NetPolicyEarnings","netEarnings");
    
digester.addSetNext("CommissionStatementVO/AgentStatementVO/AgentEarningsVO","setAgentEarning","com.equitrust.commissionloader.beans.AgentEarning");
    
digester.addSetNext("CommissionStatementVO/AgentStatementVO","addAgentStatement","com.equitrust.commissionloader.beans.AgentStatement");
    return digester;
}

private void clearCommissionStatement(CommissionStatement 
commissionStatement) {
        Iterator itr = commissionStatement.getAgentStatements().iterator();
        while(itr.hasNext()) {
            AgentStatement agentStatement = ((AgentStatement)itr.next());
            AgentEarning agentEarning = agentStatement.getAgentEarning();
            agentEarning=null;
            AgentInfo agentInfo = agentStatement.getAgentInfo();
            agentInfo=null;
            clearAgentStatementDetails(agentStatement);
        }
       
    }

Thanks,

Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [digester] Digester pinning objects in memory

Posted by Matt Goodwin <mg...@metalexis.com>.
Thanks for the reply.  Since I have the option of moving to 1.7 I think 
I will.  I'll keep searching for the answer, but it's not immediately 
clear to me how I am holding a reference to Digester since I am 
declaring it locally in a method (so it should go out of scope).  Also, 
I'm a little concerned because the code I wrote is pretty basic and it 
basically follows all the tutorials out on the web.  I'm creating and 
using the digester in the loop and so I'm curious if I'm seeing stuff 
that others aren't because I'm reading multiple files and creating 
objects from them while others are just reading one config file and the 
memory problem isn't manifesting itself.  Following occam's razor though 
your explanation is probably what is really going on.

Thanks,

Matt

Simon Kitching wrote:

>On Tue, 2005-07-05 at 16:48 -0500, Matt Goodwin wrote:
>  
>
>>I am using commons-digester for creating some objects from some xml 
>>files.  When I look at this with JProbe Digester (and some other 
>>internal stuff are still referencing the object that is parsed.  The 
>>code is as follows, any help would be greatly appreciated: 
>>    
>>
>
>Digester does keep a reference to the "root" object it creates. You can
>clear this via a call to:
>  Digester.resetRoot (since 1.7 only).
>
>I don't see any other way that Digester could retain references to
>created objects.
>
>However this shouldn't be relevant; after you use the Digester object,
>there shouldn't be any references to it. So the Digester will get
>garbage-collected and therefore the "root" object isn't prevented from
>being garbage-collected. It would therefore appear that your code is
>holding on to the Digester reference after it has been used; if you fix
>this then your problem should go away anyway.
>
>Regards,
>
>Simon
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [digester] Digester pinning objects in memory

Posted by Simon Kitching <sk...@apache.org>.
On Tue, 2005-07-05 at 16:48 -0500, Matt Goodwin wrote:
> I am using commons-digester for creating some objects from some xml 
> files.  When I look at this with JProbe Digester (and some other 
> internal stuff are still referencing the object that is parsed.  The 
> code is as follows, any help would be greatly appreciated: 

Digester does keep a reference to the "root" object it creates. You can
clear this via a call to:
  Digester.resetRoot (since 1.7 only).

I don't see any other way that Digester could retain references to
created objects.

However this shouldn't be relevant; after you use the Digester object,
there shouldn't be any references to it. So the Digester will get
garbage-collected and therefore the "root" object isn't prevented from
being garbage-collected. It would therefore appear that your code is
holding on to the Digester reference after it has been used; if you fix
this then your problem should go away anyway.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org