Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2007

Tip: Looking for answers? Try searching our database.

Memory Leak in java with LinkedBlockingQuene

Thread view: 
sss.zhou@gmail.com - 08 Jul 2007 10:50 GMT
Memory Leak in with LinkedBlockingQuene

    I have three questions which are memory leak and java GC concerned.

=======================================================

   I knew there must be some memory leaks in my program. I discovered
that the instances of LinkedBlockingQuene@Node,
LinkedBlockingQuene@Segment and others was increased continuously (By
JProfiler) and will not decrease even after all requests were
processed. First I thought if there were still some elements I forgot
to remove, then I checked all the LinkedBlockingQuene count and they
are all zero.

   I wanted to ask why @Node alive when the Quene is zero?

   BTW: I was a little puzzled by the LinkedBlockingQuene::clear()
function.
   It just set head and last to null and if all the @Nodes in the
middle are alive after called it.

   I think Sun would not do such sunny thing, so why it work well?
   /**
    * Atomically removes all of the elements from this queue.
    * The queue will be empty after this call returns.
    */
   public void clear() {
       fullyLock();
       try {
           head.next = null;
       assert head.item == null;
       last = head;
           if (count.getAndSet(0) == capacity)
               notFull.signalAll();
       } finally {
           fullyUnlock();
       }
   }

========================================================

   The following content is Java GC concerned.

   After I had done some test for some time, the count of the @Node
instance was 1000 (for example), then I stopped sending any request to
my server, then the count of the @Node kept 1000. But when I did a
full gc (by Profiler), the count changed to 800 (for example) and kept
800 after many times full gc.

   My question is if the 200 instance can by free why JVM gc don't
free it in a idle time.  If there are some error in my codes that VM
gc can't free it in a regular way and only can free it in Full GC.

========================================================

   After I repaired the memory linked in my app. If Full GC (by VM or
not by call system.gc()) can by avoided?

   I assigned 2G memory for my java App. After 10~12 hours its memory
will reach about 2G and VM did Full gc automatically. The used memory
decrease to 1.4G but it cost 20s and during this time my app was
unresponsive which was not allowed.

   here is gc log:
   [GC 1963039KK->1663039K(2097152K), 0.0445726 secs]
   [Full GC 1963039K->1484445K(2097152K), 20.9461786 secs]
sss.zhou@gmail.com - 08 Jul 2007 14:58 GMT
Sorry for spelling mistake
LinkedBlockingQuene actually is : LinkedBlockingQueue
Tom Hawtin - 08 Jul 2007 15:49 GMT
>     I knew there must be some memory leaks in my program. I discovered
> that the instances of LinkedBlockingQuene@Node,
[quoted text clipped - 3 lines]
> to remove, then I checked all the LinkedBlockingQuene count and they
> are all zero.

There doesn't appear to be a LinkedBlockingQueue.Segment.

>     I wanted to ask why @Node alive when the Quene is zero?

Where are the Nodes referenced from? Perhaps they haven't be collected
yet. 1.6 seems to be better in this regard than 1.5.

>     BTW: I was a little puzzled by the LinkedBlockingQuene::clear()
> function.
>     It just set head and last to null and if all the @Nodes in the
> middle are alive after called it.

head*.next* to null. There should be no other references to the nodes as
far as I can see.

>     My question is if the 200 instance can by free why JVM gc don't
> free it in a idle time.  If there are some error in my codes that VM
> gc can't free it in a regular way and only can free it in Full GC.

You wouldn't want Java processors to take 100% CPU all the time, would
you? Doesn't make sense to run GC unnecessarily.

>     I assigned 2G memory for my java App. After 10~12 hours its memory
> will reach about 2G and VM did Full gc automatically. The used memory
> decrease to 1.4G but it cost 20s and during this time my app was
> unresponsive which was not allowed.

There are many options for tuning GC in Sun's implementations.

Also Sun has a real-time implementation (Java RTS[1]). Azul has some
pause-free kit. And I believe BEA has a pause-free JRE.

Tom Hawtin

[1] http://java.sun.com/javase/technologies/realtime/
Roedy Green - 08 Jul 2007 17:06 GMT
On Sun, 08 Jul 2007 02:50:22 -0700, "sss.zhou@gmail.com"
<sss.zhou@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>    BTW: I was a little puzzled by the LinkedBlockingQuene::clear()
>function.
>    It just set head and last to null and if all the @Nodes in the
>middle are alive after called it.

If that happened it means something ELSE besides the queue is pointing
to those elements, unless there is a Sun bug.

If you have some sort of chain between the objects, if only one is
kept alive, all will be.

--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.