[ 
https://issues.apache.org/jira/browse/SLING-12259?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sumanta Pakira updated SLING-12259:
-----------------------------------
    Description: 
When the model cache is enabled, then the adapter cache map keeps on growing 
which caused memory leaks. 

For example, In an application when adapting to a resource of type dam:Asset 
then in this [line of 
code|https://github.com/apache/sling-org-apache-sling-models-impl/blob/master/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L351]
 the Map keeps on growing. Because WeakHashMap gets Garbage collected faster, 
so the values are removed but the keys remain. 

 

One way to solve this would be, some housekeeping to remove key-value pairs 
that have had their {{SoftReferences}} cleared. 

The approach I think could be one map that maps between the cache key and weak 
referenced values and one in the opposite direction mapping between the weak 
referenced values and the keys and reference queue and a cleanup thread.

If this sounds ok then I can create PR.

 

  was:
When the model cache is enabled, then the adapter cache map keeps on growing 
which caused memory leaks. 

For example, In an application when adapting to a resource of type dam:Asset 
then in this [line of 
code|https://github.com/apache/sling-org-apache-sling-models-impl/blob/master/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L351]
 the Map keeps on growing. Because WeakHashMap value gets Garbage collected 
faster, so the values are removed but the keys remain. 

 

One way to solve this would be, some housekeeping to remove key-value pairs 
that have had their {{SoftReferences}} cleared. 

The approach I think could be one map that maps between the cache key and weak 
referenced values and one in the opposite direction mapping between the weak 
referenced values and the keys and reference queue and a cleanup thread.

If this sounds ok then I can create PR.

 


> ModelFactory adatpercache does not cleanup keys when weakreference are 
> collectd
> -------------------------------------------------------------------------------
>
>                 Key: SLING-12259
>                 URL: https://issues.apache.org/jira/browse/SLING-12259
>             Project: Sling
>          Issue Type: Bug
>          Components: Sling Models
>            Reporter: Sumanta Pakira
>            Priority: Major
>
> When the model cache is enabled, then the adapter cache map keeps on growing 
> which caused memory leaks. 
> For example, In an application when adapting to a resource of type dam:Asset 
> then in this [line of 
> code|https://github.com/apache/sling-org-apache-sling-models-impl/blob/master/src/main/java/org/apache/sling/models/impl/ModelAdapterFactory.java#L351]
>  the Map keeps on growing. Because WeakHashMap gets Garbage collected faster, 
> so the values are removed but the keys remain. 
>  
> One way to solve this would be, some housekeeping to remove key-value pairs 
> that have had their {{SoftReferences}} cleared. 
> The approach I think could be one map that maps between the cache key and 
> weak referenced values and one in the opposite direction mapping between the 
> weak referenced values and the keys and reference queue and a cleanup thread.
> If this sounds ok then I can create PR.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to