-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
7
-
x86
-
windows_xp
FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
The java.util.LogManager was reported to hold strong references to logger instances and hence is a potential memory leak. Now this was fixed by replacing the strong with weak references in a normal hashtable (I refer to the evaluation of Bug 4811930). The problem with this fix is that stale entries are never removed. Only when a logger is accessed per name the hasmap entry is potentially removed (given the weak reference is stale). Simply fetching loggers with changing names leads to an out of memory error.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The LogManager has to expunge stale entries systemacially and the memory usage should not increase when no references to the fetched loggers are held.
ACTUAL -
Memory consumption steadily increases leading to an out of memory.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread main.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestLogManager
{
public static void main(String[] args)
{
long i=0;
while(true)
{
Logger.getLogger("logger_"+(i++));
if(i%10000==0)
{
System.out.println("Mem: "+(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));
}
}
}
}
---------- END SOURCE ----------
A DESCRIPTION OF THE PROBLEM :
The java.util.LogManager was reported to hold strong references to logger instances and hence is a potential memory leak. Now this was fixed by replacing the strong with weak references in a normal hashtable (I refer to the evaluation of Bug 4811930). The problem with this fix is that stale entries are never removed. Only when a logger is accessed per name the hasmap entry is potentially removed (given the weak reference is stale). Simply fetching loggers with changing names leads to an out of memory error.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The LogManager has to expunge stale entries systemacially and the memory usage should not increase when no references to the fetched loggers are held.
ACTUAL -
Memory consumption steadily increases leading to an out of memory.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread main.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestLogManager
{
public static void main(String[] args)
{
long i=0;
while(true)
{
Logger.getLogger("logger_"+(i++));
if(i%10000==0)
{
System.out.println("Mem: "+(Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory()));
}
}
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-6942989 Memory leak of java.lang.ref.WeakReference objects
- Closed