You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by "Archie Cobbs (JIRA)" <ji...@apache.org> on 2008/04/04 20:47:24 UTC

[jira] Created: (IVY-791) Memory leak in ModuleRevisionId.java

Memory leak in ModuleRevisionId.java
------------------------------------

                 Key: IVY-791
                 URL: https://issues.apache.org/jira/browse/IVY-791
             Project: Ivy
          Issue Type: Bug
          Components: Core
    Affects Versions: 2.0.0-beta-2
            Reporter: Archie Cobbs


In ModuleRevisionId.java an attempt is made to create a "canconical instance" cache like {{String.intern()}} using this static field:

{noformat}
private static final Map/*<ModuleRevisionId, ModuleRevisionId>*/ CACHE = new WeakHashMap();
{noformat}
This doesn't work: each entry is both a key and a value, so the strong reference to the key will never allow the weak reference to the value to be the only remaining reference, and so entries will never be dropped.

You have to wrap the keys in a WeakReference.

See [Classpath's implementation of String.intern()|http://cvs.savannah.gnu.org/viewvc/classpath/vm/reference/java/lang/VMString.java?root=classpath&view=markup] for an example.



-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (IVY-791) Memory leak in ModuleRevisionId.java

Posted by "Maarten Coene (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/IVY-791?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Maarten Coene resolved IVY-791.
-------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0-RC1
         Assignee: Maarten Coene

Updated the code as you suggested.
Thanks for reporting this.

> Memory leak in ModuleRevisionId.java
> ------------------------------------
>
>                 Key: IVY-791
>                 URL: https://issues.apache.org/jira/browse/IVY-791
>             Project: Ivy
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0.0-beta-2
>            Reporter: Archie Cobbs
>            Assignee: Maarten Coene
>             Fix For: 2.0-RC1
>
>
> In ModuleRevisionId.java an attempt is made to create a "canconical instance" cache like {{String.intern()}} using this static field:
> {noformat}
> private static final Map/*<ModuleRevisionId, ModuleRevisionId>*/ CACHE = new WeakHashMap();
> {noformat}
> This doesn't work: each entry is both a key and a value, so the strong reference to the key will never allow the weak reference to the value to be the only remaining reference, and so entries will never be dropped.
> You have to wrap the keys in a WeakReference.
> See [Classpath's implementation of String.intern()|http://cvs.savannah.gnu.org/viewvc/classpath/vm/reference/java/lang/VMString.java?root=classpath&view=markup] for an example.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (IVY-791) Memory leak in ModuleRevisionId.java

Posted by "Archie Cobbs (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/IVY-791?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12585737#action_12585737 ] 

Archie Cobbs commented on IVY-791:
----------------------------------

Sorry, I said that backwards speaking of key vs. value.

It's the strong reference to the _value_ that causes the weak reference to the _key_ to never be cleared.

The fix is to wrap the values (not the keys) in WeakReferences.


> Memory leak in ModuleRevisionId.java
> ------------------------------------
>
>                 Key: IVY-791
>                 URL: https://issues.apache.org/jira/browse/IVY-791
>             Project: Ivy
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0.0-beta-2
>            Reporter: Archie Cobbs
>
> In ModuleRevisionId.java an attempt is made to create a "canconical instance" cache like {{String.intern()}} using this static field:
> {noformat}
> private static final Map/*<ModuleRevisionId, ModuleRevisionId>*/ CACHE = new WeakHashMap();
> {noformat}
> This doesn't work: each entry is both a key and a value, so the strong reference to the key will never allow the weak reference to the value to be the only remaining reference, and so entries will never be dropped.
> You have to wrap the keys in a WeakReference.
> See [Classpath's implementation of String.intern()|http://cvs.savannah.gnu.org/viewvc/classpath/vm/reference/java/lang/VMString.java?root=classpath&view=markup] for an example.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.